i have made a script where you select a team “red” or “blue” but the script won’t work i don’t know how to fix it because it works 1 time and doesn’t work the 2nd time
here is the script:
1. plr = game:GetService("Players").LocalPlayer
2. ws = workspace
3. red1 = ws.Red1
4. red2 = ws.Red2
5. red3 = ws.Red3
6. red4 = ws.Red4
7. script.Parent.MouseButton1Click:Connect(function()
8. plr.Team = game.Teams.Red
9. script.Parent.Parent.Visible = false
10. print(plr.Name.. "'s Team Is Set To ".. plr.Team.Name)
11. task.wait(.2)
12. plr.Character:MoveTo(red1.Position or red2.Position or red3.Position or red4.Position)
13. local hum = plr.Character:FindFirstChild("Humanoid")
14. hum.StateChanged:Connect(function(_oldState, newState)
15. if newState == Enum.HumanoidStateType.Dead then
16. plr.Team = game.Teams.Spectators
17. print(plr.Name.. "Has Been Eliminated. They Will Be Playing The Next Match While Waiting !")
18. elseif plr.Team == game.Teams.Lobby then
19. print(plr.Name.. "Has Been Eliminated. They Will Be Playing The Next Match While Waiting !")
20. plr.Team = not game.Teams.Spectators
21. end
22. end)
23. end)
explanation:
from red1 to red4 all of them are spawnlocations
plr is the player obvously
so basically i used task.wait(.2) for it to set the player team otherwise it won’t
and the line of
plr.Character:MoveTo(red1.Position or red2.Position or red3.Position or red4.Position)
doesn’t work as im trying to make the player spawn randomly into one of the spawnlocations to prevent player stacks
and in line 20 “plr.Team = not game.Teams.Spectators” means if the player has the lobby role and he dies then the spectator role won’t be given to him