Attempt To Index Number With Value

So I made this sword script, but this error keeps coming up

17:02:18.934 - Players.Player2.Backpack.Short Stick.dealDamage:11: attempt to index number with 'Value'

script.Parent.blade.Touched:Connect(function(p)
	
	local CanDamage = script.Parent.CanDamage.Value
	
		if CanDamage == true and p.Parent:FindFirstChild("Humanoid") then
		CanDamage = false	
		
			
		p.Parent.Humanoid:TakeDamage(100)
		if p.Parent.Humanoid.Health.Value <= 0 then
			local player = script.Parent.Parent.Parent
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1
		end
    	wait(1)
    		CanDamage = true
    	end
end)
6 Likes

uhh

Humanoids have a property named Health.

But you have a Health value in your humanoid…

I think the script’s getting confused…

Try renaming the Value and see what happens

Yeah. I updated his code:

script.Parent.blade.Touched:Connect(function(p)
	
	local CanDamage = script.Parent.CanDamage.Value
	
		if CanDamage == true and p.Parent:FindFirstChild("Humanoid") then
		CanDamage = false	
		
			
		p.Parent.Humanoid:TakeDamage(100)
		if p.Parent.Humanoid.Health <= 0 then
			local player = script.Parent.Parent.Parent
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1
		end
    	wait(1)
    		CanDamage = true
    	end
end)
5 Likes

Thanks! Also how can I find the player that owns the weapon. local player = script.Parent.Parent.Parent isn’t working

Show me the location of the script in explorer.

The script is dealDamage

Change

local player = script.Parent.Parent.Parent

to

local player = game.Players:FindFirstChild(script.Parent.Parent.Name)

3 Likes