Skip to content

Instantly share code, notes, and snippets.

Avatar

Shilo Shilo

View GitHub Profile
@Shilo
Shilo / CastCPPVoidToNil.lua
Last active Sep 22, 2022
Roblox studio scripting tricks. (Examples)
View CastCPPVoidToNil.lua
local function test()
end
typeof( (test()) )
@Shilo
Shilo / NilNothingTest.lua
Created Sep 17, 2022
Nothing to nil casting test in LUA.
View NilNothingTest.lua
function testNil() return nil end
function testNothing() end
print( type( (testNil()) ) )
print( type( (testNothing()) ) )
print( type( testNil() ) )
print( type( testNothing() ) )
@Shilo
Shilo / CollisionGroupManager.lua
Last active Sep 16, 2022
Collision group manager that allows automatically setting collision groups via Instance Attributes (CollisionGroup) in Roblox Studio.
View CollisionGroupManager.lua
local COLLISION_GROUP_ATTR_NAME = "CollisionGroup"
local RECURSIVE_PLAYER = true
local RECURSIVE_NON_PLAYER = true
local PhysicsService = game:GetService("PhysicsService")
local function IsValidCollisionGroup(collisionGroup)
return collisionGroup and #collisionGroup > 0
end
@Shilo
Shilo / Example.lua
Last active Sep 16, 2022
Flexible gui tooltip system for Roblox Studio.
View Example.lua
local Tooltip = require(game.ReplicatedStorage.Tooltip)
local tooltipGui = script.Parent
local tooltipTextLabel = tooltipGui.Text
local offset = Vector2.new(16, 0)
local maxSize = Vector2.new(200, math.huge)
local tooltip = Tooltip.new(tooltipGui, tooltipTextLabel, offset, maxSize)
tooltip:AutoShow(script.Parent.Parent)
@Shilo
Shilo / ClickToMove.lua
Created Sep 14, 2022
Click to move example in Roblox Studio.
View ClickToMove.lua
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local effect = game.ReplicatedStorage.ClickToMoveEffect
local heartbeatSignal = nil
local function OnClickToMoveTick()
local hit = player:GetMouse().Hit
if not hit then return end
@Shilo
Shilo / ToolHelpers.lua
Created Sep 14, 2022
Tool helper methods to get player and character objects in Roblox Studio.
View ToolHelpers.lua
local function GetPlayerFromTool(tool)
return game:GetService("Players"):GetPlayerFromCharacter(tool.Parent) or tool:FindFirstAncestorWhichIsA("Player")
end
local function GetCharacterFromTool(tool)
local player = GetPlayerFromTool(tool)
return player and player.Character
end
@Shilo
Shilo / Lerp.lua
Created Sep 14, 2022
Lua function to lerp between min and max numbers.
View Lerp.lua
local function Lerp(min, max, alpha)
return (max - min) * alpha + min
end
@Shilo
Shilo / TestTableComparison.lua
Created Sep 11, 2022
Test for shallow comparing tables in Roblox Studio.
View TestTableComparison.lua
local function TestTableComparison(eq)
local function ComparableTable(instance)
return setmetatable(instance, { __eq = eq })
end
local a = ComparableTable({ 1, 2, 3, "banana", "apple", 4, 5 })
local b = ComparableTable({ 1, 2, 3, "banana", "apple", 4, 5 })
local c = ComparableTable({ 1, 2, 3, "banana", "apple", 4, 5 })
local d = ComparableTable({ 1, 2, 3, "banana", "orange", 4, 5 })
@Shilo
Shilo / LeaderstatsDataStoreManager.lua
Last active Sep 12, 2022
Dynamic persistent leaderstats via DataStore. (ModuleScript in Roblox Studio).
View LeaderstatsDataStoreManager.lua
local DataStoreService = game:GetService("DataStoreService")
local leaderstatsDataStore = DataStoreService:GetDataStore("Leaderstats")
local Self = {}
function Self.add(player)
local success, leaderstatsData = pcall(function()
return leaderstatsDataStore:GetAsync(player.UserId)
end)
@Shilo
Shilo / PartTooltip.lua
Last active Sep 12, 2022
Mouse tooltip for showing name of hovered part. (StarterGui LocalScript in Roblox Studio)
View PartTooltip.lua
local RunService = game:GetService("RunService")
local TextService = game:GetService("TextService")
local tooltip = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tooltipSizeOffset = tooltip.AbsoluteSize - tooltip.Text.AbsoluteSize
local function GetWhitelistedMouseTarget()
local target = mouse.Target