Im trying to make a tool that removes a specific model when they collide with each other but I keep getting this error message in the output. How can I fix this?
local tool = script.Parent local handle = tool:WaitForChild("Handle") local w = workspace:GetChildren()
tool.Activated:Connect(function() local str = Instance.new("StringValue") str.Name = "toolanim" str.Value = "Slash" str.Parent = tool wait(2) end)
handle.Touched:Connect(function(hit) if w[hit].Name == "mushroom 1" then w[hit]:Remove() wait(30) end end)
The problem lies in the following line:
handle.Touched:Connect(function(hit) if w[hit].Name == "mushroom 1" then w[hit]:Remove() wait(30) end end)
Short answer: w[hit]
doesn't exist.
Long answer: The hit
argument is an Instance
, whereas the GetChildren
returns a numbered array.
You have to replace w[hit]
with just hit
. Again, I'm not sure this will work, because I don't have the full context.
Try this:
handle.Touched:Connect(function(hit) if hit.Name == "mushroom 1" then hit:Remove() wait(30) end end)