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

How would you make a script teleport a player after a certain time?

Asked by 6 years ago

so im making a game where a script teleport's players to another game after a certain time, it would also only teleport them if there playing value (a bool value) is true, but im not so sure how to do that ._. here is the script i have so far for main script (i already maid a counting script):

while wait() do
    if game.Workspace:WaitForChild("PlayerPlaying").Value >= 1 then
    if script.Parent.Parent:WaitForChild("Time").Value > 0 then
    script.Parent.Text = script.Parent.Parent:WaitForChild("Time").Value
    elseif script.Parent.Parent:WaitForChild("Time").Value == 0 then 
        script.Parent.Text = "0"
        wait(1)
        script.Parent.Text = "Teleporting Players!"
        wait(2)
        -- this is where it would check if the players bool value "Playing" is true
        -- this is where the script would teleport the players, but im not sure how to do that :/
    end
    else
        script.Parent.Text = "Not Enough Players!"
    end
end
0
This will make your life a whole lot easier: http://wiki.roblox.com/index.php?title=Teleporting_Between_Places secretboy6 68 — 6y
0
oof, thanks! cruizer_snowman 117 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

First, create a boolvalue in the player if you haven't already and name it whatever you want. This can be done by putting this in a server script:

game.Players.PlayerAdded:connect(player) --this is so all players will be affected by this function
    local playerValues = Instance.new("Folder", player) --the second parameter determines the parent of the object you are creating
    playerValues.Name = "playerValues" --this is done to keep all your values of the player in a nice neat spot though it's not the most secure

    local playing = Instance.new("Bool Value", playerValues)
    playing.Name = "playing" --this inserts inside the playerValues folder and obviously names the bool value 
end

now in your teleporting script, you'll want to be looking at all the players and see which player has a true "playing" value and ignoring the one's that don't. this can be done by using a for loop such as this one:

local players = game:GetService("Players") --setting all the variables so less confusion
local allPlayers = players:GetChildren()

for i,v in pairs(allPlayers) do
    if v.playerValues:WaitForChild("playing").Value == true then
        print(v.Name) --this will print each player's name that has a playing value as true
        --you can then put teleporting code here
    end
end

keep in mind the code that determines whether the player is playing or not falls on you.

for teleporting which i think you mean from one place to the other, each place has to fall under the SAME game OR you can teleport to another games STARTING*** PLACE and the starting place only. the guide for teleporting places is on the wiki here: http://wiki.roblox.com/index.php?title=Teleporting_Between_Places

0
Will try and tell you if it works or not, Thanks! cruizer_snowman 117 — 6y
0
Wont work :/ cruizer_snowman 117 — 6y
Ad

Answer this question