Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[FilteringEnabled] How to kill my own character?

Asked by 6 years ago
Edited by RubenKan 6 years ago

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?

1
You can force break a players joins in a local script which will cause the player to die User#5423 17 — 6y
0
I edited your title so that it doesnt sound like suicide. Kaythxbye. RubenKan 3615 — 6y
0
you can just reset your character? D: GameBoyOtaku 63 — 6y

3 answers

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago
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)


0
For some reason this still won't work. Is it anything to do with clicking the GUI button? SimpleArrows -5 — 6y
0
I even switched the code in the event to print'working' but it didn't print anything. Something's wrong with it... SimpleArrows -5 — 6y
0
This is bad practice. You should use the Character property of the Player object. hiimgoodpack 2009 — 6y
0
Also, what if https://www.roblox.com/users/1348586/profile joins the game? Will they not be able to play D: hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago

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)
Log in to vote
0
Answered by
Sir_Melio 221 Moderation Voter
6 years ago

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)

Answer this question