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

Can anyone help me with this script?

Asked by
TopDev 0
10 years ago

Problem is it only teleports one player out of all players to the position.

while true do
    wait(30)
mapDirectory = game.ServerStorage.Maps
local maps = mapDirectory:getChildren()
if #maps == 0 then
    print("No maps found.... disabling script to prevent script error.")
    script.Disabled = true
    return
end
local pickedMap = maps[math.random(1, #maps)]
okclone = pickedMap:clone()
okclone.Parent = game.Workspace
local msg = Instance.new("Message", game.Workspace)
msg.Text = "Obby chosen ; " ..pickedMap.Name
wait(2)
msg:remove()
for i,v in pairs(game.Players:GetPlayers()) do -- gets players
    x = okclone.TeleTo.Position.X -- get's teleto's x
    y = okclone.TeleTo.Position.Y + 1  -- get's teleto's y and add's +1 to spawn them in the air a bit
    z = okclone.TeleTo.Position.Z  -- get's teleto's z
    v.Character.Torso.CFrame = CFrame.new(x, y, z) -- teleports all players to TeleTo
wait(25)
okclone:remove()
v.Character.Torso.CFrame = CFrame.new(game.Workspace.Lobby.TeleTo.Position)
end
end

1 answer

Log in to vote
0
Answered by 10 years ago

Please upvote my rep and/or vote this as the correct answer is this helped you or worked.

The problem is that it waits 25 seconds and removes okclone and teleports them back to the lobby for each player. I will have two fixes depending on what you want:

If you would like it to wait 25 seconds per player but do it for all of the players:

while true do
    wait(30)
mapDirectory = game.ServerStorage.Maps
local maps = mapDirectory:getChildren()
if #maps == 0 then
    print("No maps found.... disabling script to prevent script error.")
    script.Disabled = true
    return
end
local pickedMap = maps[math.random(1, #maps)]
okclone = pickedMap:clone()
okclone.Parent = game.Workspace
local msg = Instance.new("Message", game.Workspace)
msg.Text = "Obby chosen ; " ..pickedMap.Name
wait(2)
msg:remove()
for i,v in pairs(game.Players:GetPlayers()) do -- gets players
    coroutine.wrap(function()
    x = okclone.TeleTo.Position.X -- get's teleto's x
    y = okclone.TeleTo.Position.Y + 1  -- get's teleto's y and add's +1 to spawn them in the air a bit
    z = okclone.TeleTo.Position.Z  -- get's teleto's z
    v.Character.Torso.CFrame = CFrame.new(x, y, z) -- teleports all players to TeleTo
wait(25)
pcall(function() okclone:remove() end)
v.Character.Torso.CFrame = CFrame.new(game.Workspace.Lobby.TeleTo.Position)
end)()
end
end

If you would like it to teleport all players then wait 25 seconds:

while true do
    wait(30)
mapDirectory = game.ServerStorage.Maps
local maps = mapDirectory:getChildren()
if #maps == 0 then
    print("No maps found.... disabling script to prevent script error.")
    script.Disabled = true
    return
end
local pickedMap = maps[math.random(1, #maps)]
okclone = pickedMap:clone()
okclone.Parent = game.Workspace
local msg = Instance.new("Message", game.Workspace)
msg.Text = "Obby chosen ; " ..pickedMap.Name
wait(2)
msg:remove()
for i,v in pairs(game.Players:GetPlayers()) do -- gets players
    x = okclone.TeleTo.Position.X -- get's teleto's x
    y = okclone.TeleTo.Position.Y + 1  -- get's teleto's y and add's +1 to spawn them in the air a bit
    z = okclone.TeleTo.Position.Z  -- get's teleto's z
    v.Character.Torso.CFrame = CFrame.new(x, y, z) -- teleports all players to TeleTo
end
wait(25)
okclone:remove()
for i,v in pairs(game.Players:GetPlayers()) do 
    v.Character.Torso.CFrame = CFrame.new(game.Workspace.Lobby.TeleTo.Position)
end
end
0
Thank you very much! TopDev 0 — 10y
0
No problem. Basscans 60 — 10y
Ad

Answer this question