Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help making a script repeat itself after a certain amount of time?

I want to make this script repeat itself after a set amount of time. I tried the repeat loop and it gave me an error. Any help would be appreciated.

wait(10)
dft = {}
local plrs = #game:GetService('Players'):GetChildren()
Debounce = true
local seek = game.Lighting.AzureSword:Clone()
function GetPlayers()
local c = game.Players:GetChildren()
for i = 1, #c do
table.insert(dft, c[i].Name)
end
end

if plrs >= 1 then
function Randomize()
GetPlayers()
local d = math.random(1, #dft)
local s = d
local m = Instance.new("Message", game.Workspace)
m.Text = "The seeker is ... "..dft[s].."!"
wait(1)
m:Remove()
local rndm = game.Players:FindFirstChild(dft[s])

if Debounce then
for index, plr in pairs(game.Players:GetPlayers()) do
local char = plr.Character or plr.CharacterAdded:wait() -- Get the character of the player

local HRP = char:WaitForChild('HumanoidRootPart') -- Wait For the HumanoidRootPart
HRP.CFrame = CFrame.new(170,1,131) -- CHange the XYZ with the position or use script.Parent.CFrame for example


end


if (rndm ~= nil) then
local Player = rndm.Character
Player:MoveTo(Vector3.new(238, 0.05, -1427))






if (rndm ~= nil) then
wait(20)
local Player = rndm.Character
Player:MoveTo(Vector3.new(170,1,131))
seek.Parent = rndm.Backpack
seek.Character.HumanoidRootPart.CFrame = rndm
end




end


end
end

while wait(10) do
print("Done waiting.")
print("Randomizing.")
Randomize()
break
end


else
local h = Instance.new("Message")
h.Parent = workspace
h.Text = "Not enough players."
wait(10)
h:Remove()
end








local h = Instance.new("Message")
h.Parent = workspace
h.Text = "Restarting game"
wait(10)
h:Remove()

1 comment

0

did you code this or stole?

2 answers

You can use an outside script that can disable it and undisable it so it will run again, every script has the property called disabled.

What you can do is use While Wait(Timing) do, this makes it where it repeats itself every once in awhile.

For example I want to print "Its been 10 seconds" I would just do this

While wait(10) do
	print("Its been 10 seconds")
end

If you want it to be every 1 second then do

While wait(1) do
	print("Its been 10 seconds")
end

If you want to constantly run the script the you should use while true do which makes it run constantly.

Hopefully this helped you out!

2 comments

0

If while true do is used, it's best to include some kind of wait() inside it, otherwise you'll just crash the server.

0

Yeah thats why I like using wait()

This discussion is preserved as it was. New answers, comments, and votes are closed.