I want to try to get the player and character so I can do things like, setting the players health or damaging them if they eat a poison apple, you get the idea!
My only issue is that I’m not entirely sure how to get the player or character. So far I’ve tried this script to get the player and set their health to nothing:
death.OnServerEvent:Connect(function(player, character)
local humanoid = player:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health - 9999
end)```
I've replaced player with character too and it still says nil..
It still hasn't worked, I've looked off other models but I can't figure out other people's code for some reason. I've also looked on the devforum, but sadly it has had nothing that would fit right in my script.
Anything is appreciated.
player is the array of the user, and placing character another in argument won’t really work. instead remove character at function the make a variable of character then type put the player then place .Character after.
should look like this:
local character = player.Character or player.CharacterAdded:Wait()
in here, you placed player:FindFirstChild("Humanoid"), so it won’t work cause there’s no humanoid on the player array at game.Players
instead change player:FindFirstChild("Humanoid") to character:FindFirstChild("Humanoid")
did you remove the character in here? death.OnServerEvent:Connect(function(player, character) cause character will be nil cause there’s no value that was passed and because that’s the first character variable
No its just a function. I named it that cause when it would be triggered (the tool is a mask) you would put it on, then you would wait 3 seconds then your health would be sent to 0, or downed by 9999.
death.OnServerEvent:Connect(function(partThatCouldKillYou)
local parent = partThatCouldKillYou.Parent
local humanoid = parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = humanoid.Health - 9999
end
end)
My problem is that when I try to get the player or character it always says nil. And I need a way to get it, and so far it would not send errors but it wouldn’t work either. Other than that it would just say its nil.