Unable to figure out how to get the Character/Player

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.

Sorry for the bad post, this is my first time using devforum :frowning:

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

Ok… So there was no errors when I tried it out but nothing really happened. What else can I try?

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

I’ve already tried this before. It said underneath the code part (if its still there…) Still an error

local tool = script.Parent

local event = tool:WaitForChild("Death")

tool.Activated:Connect(function(player, character)
	event:FireServer()
end)

this is my local script by the way. I have a remote event inside the tool.

tool.Activated

you can use that function for normal script but in your parameters at

tool.Activated:Connect(function(player, character)

you put player, character the event must not receive the player/ character. the normal script must receive it.

They both have player, character inside the ( )'s. Is that bad?

it’s not bad if you have to fire the event back like

client > server > client

Alright, then I don’t think the issue is the player, character part… So finding the character is just a matter of adding this?

local character = player.Character or player.CharacterAdded:Wait()

Cause whenever I do that, it never prints any errors it just doesn’t work.

correct

Can’t chat any more longer

wdym cant chat any more longer?

don’t worry it’s offtopic cause i can’t chat less than 3[0 characters but i will try to brain storm what’s causing the problem.

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.

You could do this

death.OnServerEvent:Connect(function(partThatCouldKillYou)
	local parent = partThatCouldKillYou.Parent
	local humanoid = parent:FindFirstChild("Humanoid")
	if humanoid then
	   humanoid.Health = humanoid.Health - 9999
    end
end)

Its not really my problem.

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.

You need to get the Parent for the part, since the ‘Character’ will touch the part that will kill you. Then, you can set the Humanoid.