Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

if statement give errors when false?

Asked by 2 years ago

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

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago

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.

0
Since it's only true or nil, if-else statements are okay. Xapelize 2658 — 2y
Ad

Answer this question