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

Trying to make all players in the game respawn after loop runs not working?

Asked by 6 years ago
Edited 6 years ago
local Map = game.Workspace.Map
local number = 5



function reloadMap()


    game.Workspace.Map.Parent = game.ReplicatedStorage
    wait(1)
    game.Workspace:ClearAllChildren()
    wait(1)
    game.ReplicatedStorage.Map.Parent = game.Workspace

for _,v in pairs(game.Players:GetPlayers()) do -- how do i make it work like i want

v:LoadCharacter()

    end 
end


while wait(number)do
reloadMap()

end

-- If there is an easier way to clear workspace without deleting the player and unwanted folders please tell me.
0
Your script ends up breaking at ClearAllChildren, Terrain can not be cleared from the Workspace, thus throwing an error stopping your script. Why clear the workspace after adding your map anyway? M39a9am3R 3210 — 6y

1 answer

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

add another for _, v in pairs loop before respawning the players and put it instead of what you have clearing the workspace now:

for _, v in pairs(workspace:GetChildren()) do
    if not game.Players:FindFirstChild(v.Name) and not v.Name == "Terrain" then --[[ Checking if the models name is a player name
]]
        v:Destroy() -- Destroys it if it isn't.
    end
end

This should destroy everything in workspace besides parts with a players name or terrain. May have spelled terrain wrong btw..

0
Im clearing the workspace for a reason, After a while in my script fighting game the workspace gets cluttered with parts and sounds, these would usually delete themselves after a few seconds but because of some weird lag or something they don't remove themselves and then cause lag for the entire server, thats why im clearing workspace then putting the map back into workspace. XxLuascriptshandsXx -3 — 6y
0
yes, that will clear everything in the workspace besides the players and the terrain which would break if you tried to clear it cmgtotalyawesome 1418 — 6y
Ad

Answer this question