mouse = game.Players.LocalPlayer:GetMouse() player = game.Players.LocalPlayer local clone = game.Workspace.turret:Clone() mouse.Move:connect(function() if mouse.Target ~= nil then if mouse.Target.Name == "m" then clone.Parent = game.Workspace clone.Anchored = true clone.CanCollide = false clone.Position = mouse.Target.Position + Vector3.new(0,1,0) else clone:Destroy() end end end)
it's supposed to make a part be cloned and put on top of a part when my mouse moves over it heres the error:
The Parent property of turret is locked, current parent: NULL, new parent Workspace line 8
What? if i take out the else part, it works fine, but then the part stays on the last part called 'm' that mouse was on. so why doesn't it work with the else?
Your problem is that any time you're not clicking on the right object, the clone gets destroyed and therefore messes up any other times you try to click.
The way we could fix this by re-cloning the part before we destroy it. Here's an example of what I mean:
if mouse.Target.Name == "m" then --Code-- else local oldclone = clone oldclone:Destroy() clone = game.Workspace.turret:Clone() end
This would effectively destroy the part, while allowing you to do whatever you want with the new clone.
This is what it would look like in your script:
mouse = game.Players.LocalPlayer:GetMouse() player = game.Players.LocalPlayer local clone = game.Workspace.turret:Clone() mouse.Move:connect(function() if mouse.Target ~= nil then if mouse.Target.Name == "m" then clone.Parent = game.Workspace clone.Anchored = true clone.CanCollide = false clone.Position = mouse.Target.Position + Vector3.new(0,1,0) elseif mouse.Target.Name ~= "turret" local oldclone = clone oldclone:Destroy() clone = game.Workspace.turret:Clone() end end end)
And there you go, it should work now.
I hope this helped, but if you still run into any problems or have any questions, please leave a comment below and I'll see what i can do.