Debounce
local debounce = false
part.Touched:Connect(function(hit)
if debounce then return end
debounce = true
-- Do something once
print("Touched!")
task.wait(2) -- Cooldown
debounce = false
end)
Protected Calls (pcall)
local success, result = pcall(function()
return ds:GetAsync("key_123")
end)
if success then
print("Data:", result)
else
warn("Error:", result)
end
Module Scripts
-- ModuleScript (in ReplicatedStorage)
local MyModule = {}
function MyModule.greet(name: string)
return "Hello, " .. name
end
return MyModule
-- Usage in another script:
local MyModule = require(RS:WaitForChild("MyModule"))
print(MyModule.greet("Steve"))
Tweening
local info = TweenInfo.new(
1, -- duration
Enum.EasingStyle.Quad, -- style
Enum.EasingDirection.Out, -- direction
0, -- repeat count
false, -- reverses
0 -- delay
)
local tween = TS:Create(part, info, {
Position = Vector3.new(0, 10, 0),
Transparency = 0.5,
})
tween:Play()
Leaderstats
Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = ls
end)
Spawn & Respawn
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
print(plr.Name .. " died")
task.wait(5)
plr:LoadCharacter()
end)
end)
end)