How do i kill the local player with a gui button?

sorry if this is too short or something but im trying to disable the script and then kill the player, in startercharacterscripts as a regular script
i have been trying for like 1 and a half hours, please help
if you need extra details just ask

3 Likes

smthing like this may help? (put in startercharacterscripts)

task.wait(5)
local char = game.Players.LocalPlayer.Character
char.Humanoid.Health = 0

I didnt understand what u want to achieve?

2 Likes

I am sorry, but I do not understand your post. From what I understand from the title, just connect a remote event from the local script in the gui button to a script(anywhere) which sets the player’s humanoid’s health to 0.

Are you able to kill the player on the client? I prefer doing it on the server.

Im using a local script in startercharacterscripts. Im still able to see the player die from server too

If you are in Startercharacterscripts, use a regular script. You can still access the character because scripts in startercharscripts are parented to the character. Local player = script.Parent.Parent. Also local scripts should not be used in startercharscripts; Only in starterplayerscripts. He is also asking how to kill the player from a gui object.

didnt work, im trying to kill the player after enabling an option

1 Like

wouldn’t that kill every player?

Here is your solution scripts(Must create remote event named KillPlayer in replicated storage)

— Local script in the button (GUI)
script.Parent.MouseButton1Click:Connect(function()

game.ReplicatedStorage.KillPlayer:FireServer()

end)

—Script in startercharacterscripts
game.ReplicatedStorage.KillPlayer.OnServerEvent:Connect(function(player)

local hum = player.Character:WaitForChild(“Humanoid”)
if hum then
hum.Health = 0
end
end)

4 Likes

You should show ur script here

Pretty easy to do. None of the extra crap is needed for this.

Put this script in StarterGui with the desired Button:

local player = game.Players.LocalPlayer
local character = player.Character
local button = script.Parent.Button

button.MouseButton1Click:Connect(function()
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end)

Note that it is used as a LocalScript.

3 Likes

It’s better practice for a beginner to use remote events.

1 Like

In this case, that’s where you’re wrong. It makes it overcomplicated for a simple kill script.

Plus, remote events aren’t that hard.

1 Like

Using a remote event, he can reuse the kill script for other occasions instead of having to right the script EVERY time he wants to kill the player. Instead he can just fire the event. It is much more simple

1 Like

In this case, You are wrong. This is a HUGE error Server scripts DO NOT run in StarterGUI. And even if they did, mousebutton1click does not run on serverscripts! This is directed towards bcman.

1 Like

The client has network ownership over their own characters so a RemoteEvent technically isn’t necessary, if a client kills its character, its death will replicate to the server.

1 Like

We already discussed that earlier, and deemed that remote events were better for replication, and learning. Bcman made a huge error in using a server script instead of a local script in startergui using mousebutton1click though.

1 Like

Yeah, then that means we can just make it a LocalScript. Also, what do you mean @CyberWiz_YT with “having to write the script every time?” It gets replicated to the player’s PlayerGui on join :joy:

Also, I edited the reply if that makes you feel any better.

A reset button should provide instant feedback (instantly kill the client’s character), network latency (caused by dependence on RemoteEvents/RemoteFunctions) is going to negatively impact a user’s experience.

I am saying for OTHER USES. I know the starter gui is replicated to each player’s playergui. I mean ANY time you want to kill a player from the client, you can just fire the event!