So im trying to get started with some GUI programming by making a simple button that, when you click it, kills you. However, i ran into some issues in finding a player's humanoid. I've tried many methods from this
Error message #1: Players.SRdeagle.PlayerGui.ScreenGui.TextButton.LocalScript:5: attempt to index upvalue 'humanoid' (a nil value)
Attempt #1:
local button = script.Parent
local plrnm = game.Players.LocalPlayer.Name
local humanoid = workspace[plrnm]:FindFirstChild('Humanoid')
local function pressed ()
humanoid.Health = 0
end
button.MouseButton1Click:Connect(pressed)
to this
Error message #2: Humanoid is not a valid member of Model
Attempt 2#
local button = script.Parent
local plr = game.Players.LocalPlayer
local character = plr.Character
local humanoid = character.Humanoid
local function pressed ()
humanoid.Health = 0
end
button.MouseButton1Click:Connect(pressed)
Both of these methods i picked up form solved questions on this site with others having the same issue, but the thing is it apparently worked when they did them. I can see that the issue in most of my attempts is that im trying to get a humanoid out of a model, but it makes no sense to me how i can't do that since i can clearly see a humanoid under a 'SRdeagle' (my roblox username) model in workspace when i start the game...
So yeah, if anyone would be kind enough to answer me it would me much appreciated.
P.S. - I have just started with lua programming as you can probably see

6 comments
Thank you for the long and thorough answer! I will try to do this. Who knew a simple KYS button would be this hard to make
You'll get the hang of it, it gets easier after a while. Shoot me a DM if you need any help with anything. MachoPiggies#3484
this is so unnecessary
Speak to me when you learn to use spacing
Thanks for the kindness, i'll hit you up if i need some help.
If it worked, feel free to mark my post as correct <3