How do I add a kill player function to a text button?

So, I have this code in my game that is the code of my play button. All the play button does is makes the loading screen not visible. The only problem I have is that I have an auto team script and team spawns. When the auto team script works, it does not spawn you in the correct spawn. That is why I want the play button to kill the player as well as playing the animation when it is clicked. I will provide an image below regarding the problem.

1 Like

if you want to kill the player its simple just use RemoteEvent and also the way you are using the main frame is not recomended because its parented to the screenGUI which is disable thus you cant see the Main frame

like for the kill button you can add a script like:

script.Parent.Activated:connect(function() 
   Event:FireServer()
end)

then for the Remote event script

Event.OnServerEvent:Connect(function(plr)
 local char =  workspace:FindFirstChild(tostring(plr.Name))
  char.Humanoid.Health = 0
end)

Did you mean button.Activated?

you can do script.Parent i forgot to put that there

1 Like

Shouldn’t it be button.MouseButton1Click?
Also wouldn’t it be better to write plr.Character?
Am i missing something?

.Activated works as well, and it works for mobile

Mousebutton1click doesnt work for mobile?

You could just use the .Character property of the player, in case the player character is not parented to the workspace

1 Like

I’m pretty sure it does :thinking:

1 Like

Ah, that’s my bad. I thought it didn’t :sweat_smile:

I have figured out how to get the kill button function script to work, but I have another question. Is it possible to make a script so that when a user joins the game, it teleports them to their spawn? The reason it brings them to the wrong spawn is because of my auto team script which makes it so that they will spawn at the main spawn. My way of avoiding this is using the reset functions, but I was just wondering if there was a way to make them teleport to their spawn on the button click?

1 Like

It is not because of the auto team script. Check the properties of the spawn and untick/uncheck the Neutral property.

I will point out, though I do not know the efficacy of this, that you can use a normal script for detecting a button’s MouseButton1Click. This allows you to bypass creating a RemoteEvent to make it work on the server.

I tested this, and it does seem to work.