So, what this script is suppose to do is when a tool hits it, it removes the anchor on the part, and then destroys it after 2 seconds, but doesn’t work. I only want it to remove the anchor and stuff if it was hit with the tool.
(Script located inside the part itself)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Handle”) then
local model = script.Parent.Parent.Crate
model.Part.Anchored = false
wait(2)
model.Part:Destroy()
end
end)
I didn’t read the entire question sorry. Here is an updated answer: You would want to remove the line of code that runs model.Part:Destroy() if you don’t want it deleted if that’s what you are asking for.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Handle") then
local model = script.Parent.Parent.Crate
model.Part.Anchored = false
end
end)
Not enough information was provided to answer this type of question. It could be issues with how your model in the workspace is set up or possibly the grouping of parts in your tool. The code theoretically should work just fine, but you were very vague in describing your issue.
I think it is best practice to have the script in the Tool itself, rather than parts. The Handle part of the Tool is also just the grip point of the character, and may not Touch the Part when used.
I understand that you may be doing things your way for a reason.
Do you have a Mesh or a Parts in the Tool? If you do, I would that to detect the Touch event.
The Touch event might not work on Anchored parts as well, so you may need to look at alternatives