Skip to content

Instantly share code, notes, and snippets.

View Sleitnick's full-sized avatar

Stephen Leitnick Sleitnick

View GitHub Profile
@Sleitnick
Sleitnick / ConvertToStringRequires.luau
Created June 8, 2025 16:07
Take instance-require lines and convert them to string-require lines
-- Add lines to here & run script
local lines = [[
local Roact = require(script.Parent.Parent.Parent.Packages.Roact)
local RoactRodux = require(script.Parent.Parent.Parent.Packages.RoactRodux)
local Constants = require(script.Parent.Parent.Plugin.Constants)
local ThemeContext = require(script.Parent.ThemeContext)
]]
-- e.g. output from above:
--[[
--!strict
local function find(parent: Instance, ...: string): Instance
local instance = parent
for i = 1, select("#", ...) do
local name = (select(i, ...))
local inst = instance:FindFirstChild(name)
if inst == nil then
error(`failed to find instance "{name}" in {instance:GetFullName()}`, 2)
--!native
--!strict
-- Source of calculations: https://gml.noaa.gov/grad/solcalc/calcdetails.html
export type SolarData = {
JulianDay: number,
JulianCentury: number,
GeometricMeanLongitudeSunDeg: number,
GeometricMeanAnomSunDeg: number,
local coolSword = game:GetService("ReplicatedStorage").Assets.Swords.CoolSword
@Sleitnick
Sleitnick / ClosestPickup.lua
Created September 26, 2023 15:02
Custom spatial query test
--!native
--!optimize 2
--[[
ClosestPickup
- LocalScript inside StarterCharacterScripts
- MAX_RADIUS is not really a radius, but rather the zone cube size
- It searches for BaseParts in the workspace with the 'Pickup' tag
- It assumes BasePart; non BaseParts with the same tag will break this test
@Sleitnick
Sleitnick / Find.lua
Created August 31, 2023 13:28
Find an instance within the Roblox game hierarchy starting at a given parent. Throws an error if not found. Optional IsA check.
--!strict
--[[
Find(parent: Instance, path: string, [assertIsA: string]): Instance
e.g.
child = Find(parent, "ChildName")
child = Find(parent, "ChildName", "BasePart")
child = Find(parent, "ChildName/Some/Nested/Object")
child = Find(parent, "ChildName/Some/Nested/Object", "BasePart")
-- Run in LocalScript context.
-- Move mouse around to see Input event ordering in the output as well.
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local lastT = 0
local function FmtTime()
local t = time()
-- MyService.lua
local MyService = {}
function MyService:DoSomething()
print("Do something")
end
return MyService
----------------------------
local MyService = {}
return MyService
-- Load all ModuleScripts within 'MyModules' that end with "Service" & call their OnStart methods.
Loader.SpawnAll(
Loader.LoadDescendants(MyModules, Loader.MatchName("Service$")),
"OnStart"
)