Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to index local 'humanoid' (a nil value) ???

attempt to index local 'humanoid' (a nil value)

local removeHealth = false

script.Parent.Touched:connect(function(otherPart)
	local character = otherPart.Parent
	local humanoid = character:FindFirstChild("Humanoid")
	
	if humanoid then
		removeHealth = true
	end
	
	while removeHealth == true do
		wait(1)
		local CurrentHealth = humanoid.Health
		local HealthToRemove = 12
		
		CurrentHealth = CurrentHealth.Value - HealthToRemove
	end
	
	script.Parent.TouchEnded:connect(function(otherPart)
		if humanoid then
			removeHealth = false
		end
	end)
end)

Any help?

1 comment

0

Is this error occurring after you're killed, before, or during?

1 answer

✓ Accepted answer

You need to 'end' your script if the toucher is not a humanoid.

if not humanoid then
return end

elseif humanoid then
removeHealth = true
end

3 comments

0

Not sure if this is gonna fix it, but most of times I had this problem.

0

Now it says: 'end' expected (to close 'function' at line 3) near 'elseif'

0

Place another 'end' after end on line 6

This discussion is preserved as it was. New answers, comments, and votes are closed.