How can I ignore an error?

I’m making a Tycoon game and I keep getting an error, which for some reason does not affect my game at all, and I wanted to implement a way to make the errors stop showing up in my output because it is quite infuriating :frowning_face:. Any kind of help is appreciated!

I sure wonder what this error could be!!

Show the error. An image.

2 Likes


I’m not sure if that helps

1 Like

That helps a lot!
Now, help me more here by sending in the script that gives the error, I’ll provide a simple fix for it.

1 Like

Here it is:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Parent == script.Parent.Parent.Parent.Parent.Drops then
		wait(0.35)
		hit.Parent:Destroy()
	end
end)

That code is so outdated but okay…

script.Parent.Touched:Connect(function(hit)
	if hit:IsDescendentOf(script.Parent.Parent.Parent.Parent.Drops) then
		task.wait(0.35)
		if hit and hit.Parent then
			hit.Parent:Destroy()
		end
	end
end)

The script you proposed just made the situation much worse, as now the gameplay is affected. I want to ask if is there a line of code I can insert to ignore the error, instead of you fixing it. The “outdated” code worked fine, and I just want to get rid of these messages for better debugging in future senarios

If you want to “ignore” an error, you can use the pcall() function.

Example:

pcall(function()
-- Your code here
end)
2 Likes

Thanks a lot! This is what I was looking for!

1 Like

In computer programming ignoring something can cause a domino effect in the future. It’s always recommended to “fix” an error rather than just slapping on a piece of tape to “hold” it from collapsing.

I’ll also tell you this that the code is outdated as roblox is going to pretty much deprecate (remove) the .Touched function so it’s recommended to make your game future proof so you won’t get confused later on.

1 Like

What should I use then?

I agree with you, but it did not affect my game a single bit, and I believe it wont be a problem in the future

I’ll fix the error as Kat said

I recommend using task.wait() instead of wait() since that’s deprecated. Because using wait(0.35) will actually wait for about 0.5 seconds or so. Using task.wait is more accurate.

Also, are you trying to destroy the player’s character? Because it’s an error it doesn’t successfully destroy the character. hit is the character’s part that got touched.

Also, you should probably write:
if script.Parent.Parent.Parent:FindFirstChild("Drops") then first before

As this prevents the error.

If you don’t want this, then you can keep the script.

2 Likes

I’m glad you asked.

There are quite a lot of methods for going about this for example:

local Part = script.Parent
local Debris = game:GetService("Debris")

local function GetTouchingParts()
	local parts = workspace:GetPartBoundsInBox(Part.CFrame,Part.Size+Vector3.one)
	return parts
end

local function DestroyParts()
	for index,part in GetTouchingParts() do
		if part:HasTag("CollectableOrb") then -- The tag can be anything but it should be set when the orb/collectable is spawned using BasePart:AddTag("TagNameGoesHere").
			Debris:AddItem(part,0.35) -- We use the Debris Service as it's better.
		end
	end
end

while true do
	task.wait(0.5)
	DestroyParts()
end

It’s a bit overwhelming, I know, but this is future-proof and performant and accurate! The BasePart.Touched event usually fails to detect parts but this system won’t.

1 Like

I actually knew that after I wrote the script and never changed it

No, hit.Parent doesn’t always mean the character, in this case, the hit is the hitbox and the parent is the box in the image I sent that was summoned by a dropper next to the conveyor belt. The if statement is here to prevent any other object from being destroyed.

I didn’t quite understand these two bits.

The error occurs because the .Touched event is faulty and when the part gets detected once, the faulty touched detects it once more which causes the error. So basically:

  • Part detected!
  • Waiting 0.35 seconds…
  • Part detected again! The same one!
  • Waiting 0.35 seconds…
  • Part was deleted!
  • After some time…
  • Part failed to delete as it was already deleted.

OH, that’s why! Thanks a lot!

Is it necessary to write this whole script, just for a simple touched event? Also, deprecated means when a class is replaced by another one. Here is proof. I can’t find also any sign of the touched event being deprecated.

Getting a part inside an area for a touched event is also a bit strange and unethical in my opinion

1 Like

It’s your choice. Not like I can control what you want to do but the script provided is better as it’s more up-to date and accurate.

Here’s a shortened version:

while true do
	task.wait(0.5)
	for index,part in workspace:GetPartBoundsInBox(script.Parent.CFrame,script.Parent.Size+Vector3.one) do
		if part:HasTag("CollectableOrb") then
			game:GetService("Debris"):AddItem(part,0.35)
		end
	end
end

I just had a few extra functions for cleanliness.

Yes, I do know that. I was talking about the event (.Touched). Not the entire function (Checking contact with parts).

1 Like

Ok, thanks a lot and I will take your replies into consideration!

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