Skip to content

Instantly share code, notes, and snippets.

View Sleitnick's full-sized avatar

Stephen Leitnick Sleitnick

View GitHub Profile
--!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"
)
--[[
Copyright © 2022 Stephen Leitnick
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.