Skip to content

Instantly share code, notes, and snippets.

View Shilo's full-sized avatar

Shilo Shilo

View GitHub Profile
@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 / 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 / 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 / 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 / StarterPlayer.lua
Last active September 6, 2022 01:36
[EXPERIMENTAL] Server script to clone children from StarterPlayer folder into Player. (Requires scripts to be disabled and have RunContext = Server, to be able to run in Player object.)
local CLONE_STARTER_PLAYER_SCRIPTS = false
local CHILDREN_BLACKLIST_NAMES = {"StarterCharacterScripts", "StarterPlayerScripts", "StarterCharacter"}
local children = {}
for _, child in game.StarterPlayer:GetChildren() do
if table.find(CHILDREN_BLACKLIST_NAMES, child.Name) then continue end
table.insert(children, child)
end
@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)
@Shilo
Shilo / ChatCommandManager.lua
Last active August 30, 2022 07:08
Flexible chat command system for Roblox Studio.
local Self = {}
Self.Prefix = "/"
Self.Separator = " "
Self.Delegate = {}
function Self.ArgumentsText(...)
return table.concat({...}, " ")
end
@Shilo
Shilo / EditorFindPart.lua
Created August 27, 2022 09:24
Command bar script for finding any part on middle click in Roblox Studio.
game:GetService("ContextActionService"):BindAction("findPart", function(_, s, o)
if s ~= Enum.UserInputState.Begin then return end
local i = game:GetService("GuiService"):GetGuiInset()
i = Vector3.new(i.X, i.Y, 0)
local p = o.Position + i
local vp = workspace.CurrentCamera:ViewportPointToRay(p.X, p.Y)
local r = workspace:Raycast(vp.Origin, vp.Direction * 1000)
@Shilo
Shilo / Holster.lua
Created August 26, 2022 10:44
Un-optimized holstering system for tools in Roblox Studio.
local holsteredTools = {}
local function HolsterTools(attachment)
local player = script.Parent.Parent.Parent
if not player:IsA("Player") then return end
local character = player.Character
if not character then return end
local tool = character:FindFirstChild(script.Parent.Name)