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

Text button GUI should kill player when clicked but doesn't, how do i fix this?

this is my first time working with filtering enabled, ive made a few small games in the past but nothing good

i made a text button gui that when clicked should kill the player. This is what im having trouble with. (feel free to call me a noob) but i cant seem to figure out how to make it function as it should, here's the script.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
local LocalPlayer = game.Players.LocalPlayer
LocalPlayer.Health = 0
end)

i know its sad i cant get the simplest function to work but eh i guess we all start somewhere

thanks for the help in advance!

2 comments

0

Wait. If your a noob then how do you know how to use events lol?

0

if you are trying to effect a "humanoid" you must mention it in your code.

1 answer

Server scripts can't access localplayer. It needs a p (additional argument in fe) in the argument/player in the argument. For more info, view the robloxwiki or youtube videos. You're welcome. And, btw you missed to define the character then the humanoid. Humanoid holds all the properties of the character.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(p) ---[[ in the argument, defines plr]]
local char = p.Character -- gets character
local hum = char:WaitForChild("Humanoid") -- gets humanoid

hum.Health = 0 -- This will make the hum's health zero
end)

2 comments

0

thank you!

0

No problem!

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