Script says a part is not there when it clearly is?

Hey devforum.

So, my script says there isn’t a part in the tool when there clearly is. If you can help me figure it out, I will be grateful. Ty!

Layout:
explorer

Error:

DetectArea is not a valid member of Tool "Workspace.PizzaArmy333.Basic Detector"
Line 1

Script:

local DetectArea = script.Parent.DetectArea --Error here
local beepSound = script.Beep
local anim = script.Animation

local canDetect = {"TestPart", "Soda Can"}

DetectArea.Touched:Connect(function(hit)
	local hum = script.Parent.Parent.Humanoid
	local loadanim = hum.Animator:LoadAnimation(anim)
	
	loadanim:Play()
	if table.find(canDetect, hit.Name) then
		beepSound:Play()
		
		if not hit:FindFirstChild("SparkleEffect") then
		    local marker = game.ReplicatedStorage.SparkleEffect:Clone()
		    marker.Parent = hit
		    marker.Position = hit.Position
		
		    wait(0.5)
		    hit.Position = script.Parent.Pos.Position
			marker.Position = hit.Position
		end
	end
end)

Do

local DetectArea = script.Parent:WaitForChild('DetectArea')

It takes a second for items inside a tool to be replicated so waiting does the trick!

Got infinite yield, still not working.

try to connect the event immediately without the variable.

Got the error again.

DetectArea is not a valid member of Tool “Workspace.PizzaArmy333.Basic Detector”

When you are in game go to your character model and check if the part exists inside of your tool

When you equip tools with parts that are not attached to a a hand, it sometimes fall out of the world. Check if they did when you equip and unequip

The part isn’t inside the tool… how can I fix this?

That means that the part is unanchared and it just falls to the void

Anchoring makes it stuck in a position. Did you mean welding?

Yes i meant that you need to weld it so it doesn’t falls

1 Like

It fixed it! Tysm! I no longer get the error

1 Like