Team Changes but not Spawn Location

  1. 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.

  2. 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.

  3. 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)

2 Likes

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! :slightly_smiling_face:

1 Like

Did you try that and did it work yet? :slight_smile:

1 Like

Oh I see. I’m not sure how to do this but I’ll try and see if it works now!

1 Like

Oh how to use remote events? Here is a post that can help you, but I will also show you how to do it in this example as well:

Anyways, put a remote event in ReplicatedStorage.

In your local script do this:

script.Parent.MouseButton1Click:Connect(function()
      game.ReplicatedStorage.RemoteEvent:FireServer()
end

In your server script, do this:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
      plr.TeamColor = BrickColor.new("Dark indigo")
      local char = plr.Character or plr.CharacterAdded:Wait()
      char:WaitForChild("Humanoid").Health = 0
end)

This should work, if you run into any errors just tell me and I will try to help if I am online. Good luck :slightly_smiling_face:

2 Likes

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.

1 Like

Is the script working for this button? If so then good :slight_smile:
Also, about your different buttons question. You can actually pass arguments into remote events. You can do something like this

game.ReplicatedStorage.RemoteEvent:FireServer("Dark indigo")
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, teamValue)
      plr.TeamColor = BrickColor.new(teamValue)
      local char = plr.Character or plr.CharacterAdded:Wait()
      char:WaitForChild("Humanoid").Health = 0
end)

That code should work as an example. :slight_smile: Again, if it doesn’t work just tell me and I will look into it more. Good luck

4 Likes

Yes that finally worked for each button! Thanks for the help, and teaching me about remote functions lol.

1 Like

An old post from 2020, but it’s still effective nowadays. Thank you so much!

1 Like