What do you want to achieve? Keep it simple and clear!
-I’m aiming to make a script that changes a player’s team when they press a button from a GUI.
What is the issue? Include screenshots / videos if possible!
-When I test the script, the team does change, but the spawn point is still the same. Even though each team has a different spawn point.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
-I tried looking it up but I didn’t find how to fix this exact situation that I’m having. Any help is appreciated.
My code for the Team Changing button:
--Changes Player's team after button click
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Name
script.Parent.MouseButton1Click:Connect(function()
game.Players[plr].TeamColor = BrickColor.new("Dark indigo")
game.Workspace[plr].Humanoid.Health = 0
script.Parent.Parent.Parent.Parent.Enabled = false
end)
You need to use a remote to tell the server to change the team. It is not replicating to the server and that is the reason behind your bug (I assume). When you respawn, the server does not see the team your client changed to, so it doesn’t use that one. Fire the server instead and put the team change code after it has been fired. Good luck!
Wow thanks! I didn’t know that remote events were also objects, and needed to be in replicated storage.
Also I was wondering is there a way to make sure a different event is fired for each of the different buttons? I have four teams with four different team changing buttons.
Is the script working for this button? If so then good
Also, about your different buttons question. You can actually pass arguments into remote events. You can do something like this