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

Uhh, problem? Player won't respawn at the new RespawnLocation I assigned. {Solved myself}

So I made a settings GUI that allows people to change their teams. However, if the player dies, they only spawn at their previous spawn location (the team they were auto-assigned with), even when I've assigned the player's new RespawnLocation.

I have two teams: Red Team and Blue Team. These teams exist ingame, and the rest of my GUI functions as I expect.

I'm giving you my code, but only the lines of code changing the teams, as my only problem is why the player doesn't respawn at the new team spawn locations, there's no other problem.

game.Players.LocalPlayer.Team = game.Teams["Red Team"]
local spawns = game.Workspace.Spawn.RedSpawn:GetChildren()
local random = math.random(1, #spawns)
game.Players.LocalPlayer.RespawnLocation = spawns[random]
game.Players.LocalPlayer.Team = game.Teams["Blue Team"]
local spawns = game.Workspace.Spawn.BlueSpawn:GetChildren()
local random = math.random(1, #spawns)
game.Players.LocalPlayer.RespawnLocation = spawns[random]

4 comments

0

Dude, make variables.

0

Math.random will always produce the same number the first time, look into adding a math.randomseed(tick())

0

@ABK2017 So apparently the algorithm is outdated and I'd consider using Random.new()?

0

*or math.randomseed()

1 answer

Nevermind. I've managed to solve it myself.

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