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

Why is player not spawning at team spawnpoint?

I am currently working on a prison game and i have created a team select/change GUI. I have programmed a script that is meant to change the player's team and kill them so they spawn at that team spawn. It all works, the player respawns at the neutral spawnpoint, which is very frustrating. The player still remains in the chosen team. I have correctly paired up the teams to their spawnpoints by making the brick colours and team colours the same. They also have the same name. I have unchecked 'Neutral'. Here is the LocalScript:

Button = script.Parent

script.Parent.Parent.Visible = true -- opens the gui

Button.MouseButton1Down:connect(function(open)
    script.Parent.Parent.Visible = false -- closes the gui

    game.Players.LocalPlayer.Team = game.Teams.Policemen
    game.Players.LocalPlayer.RespawnLocation = 	game.Workspace.Policemen
    local plr = game.Players.LocalPlayer.name
    local plrfound = game.Workspace:FindFirstChild(plr)
    plrfound.Humanoid.Health = 0
end)

Please help me out Thanks

2 comments

0

i think not sure tho that on line 9 at the end add .Position

0

This doesn't work.

1 answer

✓ Accepted answer

Your script isn't working due to FilteringEnabled. You're changing the player's team through a local script, and that does not replicate to the server, so in reality the player's team has not actually changed.

The solution is to use remote events. Remote events allow players to request for code to run on the server, in simple terms. Here's how you would use them in your case:

-- server
local teams = game.Teams
local changeTeam -- remote

changeTeam.OnServerEvent:connect(function(player, name)
	local team = teams:FindFirstChild(name)
	if team then
		player.Team = team
	end
end)

-- client
local changeTeam -- remote
local button

button.MouseButton1Click:connect(function()
	changeTeam:FireServer(button.Name) -- or whatever you come up with to define what to send
end)

Set the variable changeTeam to where the RemoteEvent is stored. Generally, RemoteEvents are stored in ReplicatedStorage as both the player and the server can access it.

I didn't write the block of code above, I did a quick google search and found this post about it.

Hope this helps.

2 comments

0

Thanks, but I don't really understand the script. I'm not sure how I can make use of this.

0

I have looked at the code again and now I do understand it. Thanks!

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