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

How can I start a scripted function on the start of the server?

I have something that has a 60 second delay and then teleports you to another place. How do I get it to start on the startup of the server? i.e. "function onStart (startup)"

^ That was my failed guess at how to do it ^ I just want the function to start when the server does (with a wait of 60 seconds - that I know how to do).

1 answer

✓ Accepted answer

Scripts run when the server starts, so if you had something like this-

wait(60)
Game.Players.StarAd.Character.Torso.CFrame = CFrame.new(0, 0, 0)

That would technically run when the server starts. I'm thinking you mean when each player joins the server, and for that you have to use the PlayerAdded event.

local Teleport = Vector3.new(0, 0, 0)
Game:GetService("Players").PlayerAdded:connect(function(plr)
	wait(60)
	if plr.Character then
		plr.Character:FindFirstChild("Torso").CFrame = CFrame.new(Teleport)
	end	
end)

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