Trying to find humanoid

i made a npc that heals you when your lesser then 90 and when i touch its right arm it doesnt heal instead it gives me this

add this directly after your touched event

local debounce = false
script.Parent.Touched:Connect(function(hut)
local humanoid = hit.Parent:FindFirstChildOfClass("humanoid") 
if humanoid then
if game.Players:GetPlayerFromCharacter(hit.Parent) == nil then return end
if not humanoid then return end
--Optional:
if humanoid.Health > 90  or debounce == true then return end
debounce = true
humanoid.Health += 10
task.wait(2)
debounce = false
end

the issue is with the structure of your code on line 16.

local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid"))

here is an expanded version for you to see the issue more clearly.

local player = game:GetService("Players"):GetPlayerFromCharacter(
    hit.Parent:FindFirstChild("Humanoid")
)

you’re passing the humanoid as the character parameter for GetPlayerFromCharacter.
here is a fixed version

local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

never mind i fixed it by removing the player and just putted hit.parent.humanoid and i putted it on the health thingy

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.