How to make player reset when hes touches switch team gui button

also give me know if this topic is wrong but i dont found solutions for this script in devforum
Hello im tried to make script by watching tutorials from youtube,Devforum,and other sources because im only builder and i cant understand scripting so im only understand basics (no good teachers like friends because they only builders or modellers even youtube cant help)
but 1 script from video didnt worked so im used another one and when its worked im tried to make player reset because set humanoid health to 0 didnt worked

so basically here was 2 teams and gui
clicking on them made you switch team but you didnt reseted or died after pressing them, devforum didnt had topics like this and videos dont has solutions
im managed to try improve it so when you click it getting closed (so you dont need button)
heres script for both teams in buttons

local player = script.Parent.Parent.Parent.Parent.Parent.Name

script.Parent.MouseButton1Click:Connect(function()
	game.Players[player].TeamColor = BrickColor.new("Steel blue")
	script.Parent.MouseButton1Click:Connect(function()
	game.Workspace.Humanoid.Health = 0
    end)
	script.Parent.Parent.Visible = false
end)
1 Like

You don’t need to address the player variable as the name of the player, just use it as the player itself and shorten it using :FindFirstAncestorOfClass and respawn the character with :LoadCharacter().

local player = script:FindFirstAncestorOfClass("Player")

script.Parent.MouseButton1Click:Connect(function()
	player.TeamColor = BrickColor.new("Steel blue")
	player:LoadCharacter()
	script.Parent.Parent.Visible = false
end)

I don’t think you can do that on client. You would need to add a remote-event.

script.Parent.MouseButton1Click:Connect(function()
-- Code here
Remoteevent:FireServer()
end)

Server Script:

RemoteEvent.OnServerEvent:Connect(function(player) -- it passes the player automatically
player.Character.Humanoid.Health = 0
end)

thanks but just i cant write scripts fully, for example i can rename some guns bullets color or damage but writing workspaces and other is hard

Kaids script actually worked (----------)

also sadly i dont understand how to use remote events to make this script work so ye