Attempt to index nil with 'JumpPower'?

I’m doing a damage you block over time but I need the player to not be able to jump and I get an attempt to index nil with ‘JumpPower’, what do I do?

my code here:

local accion = "false"
script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	humanoid.JumpPower = 0
	accion = "true"
	
	while true do
		wait(1)
		if accion == "true" then
			humanoid:TakeDamage(0.4)
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	humanoid.JumpPower = 0
	accion = "false"
	wait(1)
	accion = "true"
end)

script.Parent.Touched:Connect(function(h)
	local d = h.Parent:FindFirstChild("Humanoid")
	if d then
		d.JumpPower = 0
	end
end)

First of all you are not checking if the hit.Paren has Humanoid at the Touched Event.

There are 2 touch events, one that does not verify and another that does, but in the 2 I get an error

Alright now I see, you are not checking the Humanoid in TouchEnded event.

Edited your script should work

local action = false
script.Parent.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        action = true
        
        while true do
            wait(1)
            if action then
                Humanoid:TakeDamage(0.4)
            end
        end
    end
end)

script.Parent.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        Humanoid.JumpPower = 0
        action = true 
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        Humanoid.JumpPower = 50
        action = false
    end
end)

I don’t know why but I don’t think any method works

I tested it on my own game and it works. Is this in a localscript or a serverscript?

is a serverscript and i don’t know why it not works

show me what it look likes (screenshot the workspace and stuff)

It is within a group but being outside the group does not work either

are you going inside the box itself? Is canTouch on?

I have verified everything and everything is in order

DamagePart.rbxm (2.9 KB) Try just pasting this in

1 Like

I can keep jumping and I don’t know why

Hi, you might want to turn this on.

1 Like

oh it work me, thanks you very much

1 Like

Thanks you too for trying to help me :smiley:

I thought he would have that on XD. I overlooked it thx for helping him.

1 Like