Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
StarAd 50
10 years ago

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

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

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)
Ad

Answer this question