So im not sure why this is happening, can someone help me
local damage = player:WaitForChild("Data").Damage
hit.Parent:FindFirstChild("npchum"):TakeDamage(damage.Value)
Thank you
So im not sure why this is happening, can someone help me
local damage = player:WaitForChild("Data").Damage
hit.Parent:FindFirstChild("npchum"):TakeDamage(damage.Value)
Thank you
It means hit.Parent.npchum doesnât exist. Consider changing FindFirstChild into WaitForChild.
In addition to what @Ty_Scripts mentioned, Iâd advise checking if it was found before trying to call TakeDamage
on the Instance just in case it never ends up in its intended spot:
local npchum = hit.Parent:WaitForChild("npchum")
if npchum then -- Only continues if "npchum" is found to ensure it doesn't error
npchum:TakeDamage(damage.Value)
end
I have a wierder situation: it said attempt to index number with âTakeDamageâ. What the **** is wrong here??? Isnât :TakeDamage() supposed to take in number???
That error is indicating that youâre calling :TakeDamage()
on a number rather than an Instance (which in this case, should be a Humanoid object).
no, i did humanoid:TakeDamage(player.Damage.Value). player.Damage.Value is 0 at the time. When I changed it to 10, it still had the error. I will try it again
it still doesnt work for some reason
The error isnât originating from the Damage Value that you input into the method, itâs happening as a result of humanoid:TakeDamage()
.
Try printing typeof(humanoid)
and see if it returns ânumberâ. If thatâs the case, then that means that the âhumanoidâ variable isnât referring to an Instance, which should be the Humanoid object when using the TakeDamage
method.
When running the code in this example, the same error that you mentioned will appear in the Output, originating from the line that says humanoid:TakeDamage(10)
because the âhumanoidâ variable contains a reference to a number and not an Instance, whereas the line that says realHumanoid:TakeDamage(50)
works as intended because the ârealHumanoidâ variable contains a reference to a Humanoid object.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local humanoid = 1
local realHumanoid = Character:WaitForChild("Humanoid")
realHumanoid:TakeDamage(50)
print("The real Humanoid has taken 50 damage points")
task.wait(5)
humanoid:TakeDamage(10)
end)
end)
oh wait HAHAHAHAHAHAHA IM SO DUMB
At first player.Damage.Value was 0. I was using humanoid.Health -= player.Damage.Value so itâs doing nothing. Then, I just changed it into humanoid.Health:TakeDamage(player.Damage.Value) and then I found out that player.Damage Value was 0 so I set it to 10 but I didnt realize that im calling takedamage on humanoid.Health LMFAOOOOOOOOOOO anyways thx for u help