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

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

Asked by 5 years ago
Edited 5 years ago

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]
0
Dude, make variables. User#25115 0 — 5y
0
Math.random will always produce the same number the first time, look into adding a math.randomseed(tick()) ABK2017 406 — 5y
0
@ABK2017 So apparently the algorithm is outdated and I'd consider using Random.new()? Mirzadaswag 110 — 5y
0
*or math.randomseed() Mirzadaswag 110 — 5y

1 answer

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

Nevermind. I've managed to solve it myself.

Ad

Answer this question