How would I ignore this error?

nothing happens with this error exept being annoying, how would i disable it? script:

game:GetService("RunService").Heartbeat:Connect(function()


	if target and target.CanGrab and target.CanGrab.Value == script.Parent.Name then
		
	
		
		local pos = hrp.Position + (mouse.Hit.Position - hrp.Position).Unit * 10

		target.BodyPosition.Position = pos
		target.CFrame = CFrame.new(Vector3.zero, mouse.Hit.LookVector)  + target.Position
		target.CFrame =  target.CFrame*CFrame.Angles(0, math.pi, 0)
		target.BodyGyro.CFrame = target.CFrame
		


	
	else 
	end
end)

1 Like

I think you need to change the first target.CanGrab to target:FindFirstChild(“CanGrab”)

The problem is that with the dot notation it’ll throw an error, whereas FindFirstChild will just return nil. Then the if check will fail if there’s no result.

Would end up with:

game:GetService("RunService").Heartbeat:Connect(function()


	if target and target:FindFirstChild("CanGrab") and target.CanGrab.Value == script.Parent.Name then
		
	
		
		local pos = hrp.Position + (mouse.Hit.Position - hrp.Position).Unit * 10

		target.BodyPosition.Position = pos
		target.CFrame = CFrame.new(Vector3.zero, mouse.Hit.LookVector)  + target.Position
		target.CFrame =  target.CFrame*CFrame.Angles(0, math.pi, 0)
		target.BodyGyro.CFrame = target.CFrame
		


	
	else 
	end
end)

Do you want to prevent the error message from showing up??

the error dosnt do anything (i think) important and it is just an annoyance preventing me from seeing the errors that matters

You can wrap your code in a pcall function like this:

game:GetService("RunService").Heartbeat:Connect(function()
    local success, _ = pcall(function()
        if target and target.CanGrab and target.CanGrab.Value == script.Parent.Name then
            local pos = hrp.Position + (mouse.Hit.Position - hrp.Position).Unit * 10
            target.BodyPosition.Position = pos
            target.CFrame = CFrame.new(Vector3.zero, mouse.Hit.LookVector) + target.Position
            target.CFrame = target.CFrame * CFrame.Angles(0, math.pi, 0)
            target.BodyGyro.CFrame = target.CFrame
        end
    end)
end)

This will help prevent the error message from being displayed.

Best regards, Xethele

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.