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

Can anyone help me with this script?

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

✓ Accepted answer

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

2 comments

0

Thank you very much!

0

No problem.

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