Can't destroy model

Destroy(), Remove() and ClearAllChildren() isn’t not working for models,
and I don’t know what to do
please help me

local cash = script.Parent.Parent.Parent.Parent.Values.Cash

script.Parent.Touched:Connect(function(hit)
	if hit:FindFirstChild("Price") then
		cash.Value += hit:FindFirstChild("Price").Value
		hit.Parent:Destroy()
	end
end)

there aren’t any warns nor errors and I really want this done

First off can I see the workspace? This might help me solve the problem

theres my tycoon:

and theres my part that should give money
image

Question is, is that function running?
Make sure that it is please!

To do this you can just put a print inside of the function and see if it works

:Remove is depracated, I recommend using :Destroy
and try adding print statements to see if it is being found

script.Parent.Touched:Connect(function(hit)
	if hit:FindFirstChild("Price") then
        print("Hello, world!")
		cash.Value += hit:FindFirstChild("Price").Value
		hit:Remove()
	end
end)

And also try this

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Price") then
        print("Hello, world!")
		cash.Value += hit:FindFirstChild("Price").Value
		hit:Remove()
	end
end)

(Using hit parents checks the model not the children in it, you can’t touch a model only baseparts (Unions, Negative Parts, Intersections, etc.)

But I already use Destroy(), I accidently put it in there because I was seeing if it would work

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Price”) then
print(“Hello, world!”)
cash.Value += hit:FindFirstChild(“Price”).Value
hit:Destroy()
end
end)
(Using hit parent checks the model not the children in it, you can’t touch a model only baseparts (Unions, Negative Parts, Intersections, etc.)

Are you telling if the model is touched?
Cause like @RedDeath981 said, models cant be touched.
It has to be a basePart

2 Likes

no if a part in the model is, but turns out i just forgot to make it so i was cheking the model’s children, not the touched part children :person_facepalming: :person_facepalming:

thank you so much it fixed it! wow i really should pay more attention lol

Never forget to add a “.Parent”
Like I used to do with kill parts when I first started.
Checking hit is a basepart
Checking hit parent is the parent (usually the characters model if you’re doing a kill part)

1 Like

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