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

if statement give errors when false?

Hello my script gives me an error when the if statement is false

local function RaycastBullet()
	local Target = mouse.target
	local Damage = 10
	
	if Target then
		if Target.Parent.Humanoid then
			Target.Parent.Humanoid:TakeDamage(Damage)
		end			
		if Target.Parent.Parent.Humanoid then
			Target.Parent.Parent.Humanoid:TakeDamage(Damage)
		end	
	end
end

1 answer

✓ Accepted answer

You should use FindFirstChild, if it detect the Instance is not there, it returns nil. You are going to make line 2 to:

local Target = mouse:FindFirstChild("target")

And it will work fine.

1 comment

0

Since it's only true or nil, if-else statements are okay.

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