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?
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)
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)