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

[FilteringEnabled] How to kill my own character?

How do I kill my own character with Filtering Enabled using RemoteEvents?

In the gui button, I did this:

(it's in a localscript)

script.Parent.MouseButton1Click:connect(function()
	game.ReplicatedStorage.events.killSelf:FireServer()
end)

Then in the event, I put this:

(normal script)

local healthplayer = game.Players.LocalPlayer.Character.Humanoid

script.Parent.OnServerEvent:connect(function(player)
		healthplayer.Health = 0
end)

Why won't it do anything when I click the button though?

3 comments

1

You can force break a players joins in a local script which will cause the player to die

0

I edited your title so that it doesnt sound like suicide. Kaythxbye.

0

you can just reset your character? D:

3 answers

game.Players.LocalPlayer

server scripts cannot access local player. To counter this, we grab the character using the players name.

local healthplayer = game.Players.LocalPlayer.Character.Humanoid

script.Parent.OnServerEvent:connect(function(player)
	local healthplayer = game.Workspace[player.Name].Humanoid
        healthplayer.Health = 0
end)


4 comments

0

For some reason this still won't work. Is it anything to do with clicking the GUI button?

0

I even switched the code in the event to print'working' but it didn't print anything. Something's wrong with it...

0

This is bad practice. You should use the Character property of the Player object.

0

Also, what if https://www.roblox.com/users/1348586/profile joins the game? Will they not be able to play D:

This should work because you didn't call the event in the serverscript, and it already calls the player within the function

LOCAL SCRIPT

local Event = game.ReplicatedStorage.events.killSelf

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

SERVER SCRIPT

local Event = game.ReplicatedStorage.events.killSelf

Event.OnServerEvent:Connect(function(player)
        player.Character.Humanoid.Health = 0
end)

kingdom5 already provided a better solution, although he misspelled "joints". You don't need a normal script to kill the local player. It can be done so like this in the LocalScript:

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.Character:BreakJoints()
end)

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