Skip to content

Instantly share code, notes, and snippets.

View Shilo's full-sized avatar

Shilo Shilo

View GitHub Profile
@Shilo
Shilo / NilNothingTest.lua
Created September 17, 2022 08:46
Nothing to nil casting test in LUA.
function testNil() return nil end
function testNothing() end
print( type( (testNil()) ) )
print( type( (testNothing()) ) )
print( type( testNil() ) )
print( type( testNothing() ) )
@Shilo
Shilo / Example.lua
Last active September 16, 2022 21:58
Flexible gui tooltip system for Roblox Studio.
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 / CollisionGroupManager.lua
Last active September 16, 2022 07:12
Collision group manager that allows automatically setting collision groups via Instance Attributes (CollisionGroup) in Roblox Studio.
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 / ClickToMove.lua
Created September 14, 2022 09:37
Click to move example in Roblox Studio.
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 September 14, 2022 08:53
Tool helper methods to get player and character objects in Roblox Studio.
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 September 14, 2022 05:25
Lua function to lerp between min and max numbers.
local function Lerp(min, max, alpha)
return (max - min) * alpha + min
end
@Shilo
Shilo / PartTooltip.lua
Last active September 12, 2022 09:05
Mouse tooltip for showing name of hovered part. (StarterGui LocalScript in Roblox Studio)
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
@Shilo
Shilo / LeaderstatsDataStoreManager.lua
Last active September 12, 2022 05:07
Dynamic persistent leaderstats via DataStore. (ModuleScript in Roblox Studio).
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 / TestTableComparison.lua
Created September 11, 2022 10:24
Test for shallow comparing tables in Roblox Studio.
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 / TagHumanoid.lua
Last active September 7, 2022 04:47
Simple damage tagging system for Roblox studio.
local Debris = game:GetService("Debris")
local function UntagHumanoid(humanoid)
local creatorValue = humanoid:FindFirstChild("creator")
if creatorValue and creatorValue:IsA("ObjectValue") then
creatorValue:Destroy()
end
end
local function TagHumanoid(humanoid, creator, duration)