I’m creating a script that adds a stat to a player after a certain amount of time, I could use wait() but I’m concerned it’s unreliable so I’m wondering if there is any other alternatives.
Script
script.Parent.MouseButton1Click:Connect(function()
if PreviewMode == true then
script.Parent.UploadText.Text = "Preview"
local String = script.Parent.Parent.Parent.IDInput.Text
local InputType = tonumber(String)
local Length = #String
if InputType ~= nil and Length == 10 then
PreviewMode = false
Preview.Visible = true
Preview.Image = "rbxassetid://2300836745"
Preview:TweenSize(UDim2.new(0.951, 0,0.013, 0))
Preview:TweenPosition(UDim2.new(0.501, 0,0.177, 0))
wait(1)
CTween:Play()
wait(.5)
Preview:TweenSize(UDim2.new(0.951, 0,0.8, 0))
Preview:TweenPosition(UDim2.new(0.501, 0,0.57, 0))
BTween:Play()
wait(1)
Preview.Image = "rbxassetid://"..String
script.Parent.UploadText.Text = " Upload "
end
else
--wait 3 seconds
--give stat
end
end)
If you don’t really care about the wait(3) being 100% exact, then it’s not an issue to use wait(3) as far as I know. The issue with wait(n) is using it without n, for example in a loop.
If you want 100% exact results, you can use a library like Promise https://eryn.io/roblox-lua-promise/lib/Installation.html and use it’s delay function (https://eryn.io/roblox-lua-promise/lib/#delay). It basically can do what you want to do, wait 3 seconds and then run the piece of code.