How to get rid of unnecessary errors in output?


I’m doing a check in the script to see if it can be done so that if the condition is not suitable, the output does not output it to me as an error?

Here is my script

script.Parent.Touched:connect(function(Hit)
	
	print(Hit.Parent.Name)
	if Hit.Parent.W3.Value then
		game.ServerScriptService.MainScript.Arriv.W3inCaf.Value = true
		print("W3 == true")
	
	end
end)

1 Like

I think tou’re trying to check whether or not Hit.Parent.W3 exists. You just have to put it into a FindFirstChild method to check for existance. So it’d look like this:

local object = Hit.Parent:FindFirstChild("W3")
if object and object.Value then
    ...
end

Just replace your if condition there with this and leave everything inside of it the same

1 Like

There’s a problem with your script, that’s why there’s an error. It’s not unnecessary, just fix it.
And if you want to catch an error, use xpcall.

1 Like
local noideawhatthisisfor = game.ServerScriptService.MainScript.Arriv.W3inCaf
script.Parent.Touched:connect(function(Hit)
	local parent = Hit.Parent;
	print(parent);
	if parent:FindFirstChild("W3") and parent.W3.Value then
		noideawhatthisisfor.Value = true
		print("W3 == true", parent.W3)
	end
end)

try this

1 Like

Thanks, it helped me eliminate a lot of unnecessary errors clogging up the output.

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