Ok so I need help with the last part of my script, it clones a model from replicated storage, moves it with the mouse and places it when I click. I need the script to repeat again after I've placed it (Not right away - I want to click to buy it again then it follows the script). I think when I use :Remove() or :Destroy() it messes up the whole script so it can only be excuted perfectly once..
So basically I need a way to Deselect the part I'm cloning after placing it once, or if you right click it will deselect..
This is in a local script
Thanks for helping!
local player = game.Players.LocalPlayer; local mouse = game.Players.LocalPlayer:GetMouse(); local player = game.Players.LocalPlayer local mouse = player:GetMouse() local b = game.ReplicatedStorage:WaitForChild("Headquarters") local clickdetector = game.Workspace:WaitForChild("Outline"):WaitForChild("ClickDetector") local HQ = b:Clone() target = mouse.Target --------------------------------------------------------------------- --------------------------------------------------------------------- mouse.KeyDown:connect(function(key) for i,child in pairs(HQ:GetChildren()) do if child:IsA "BasePart" then key = key:lower() if key == 'r' then child.Rotation = child.Rotation + Vector3.new(0,90,0)--Rotate end end end end) function temp () b:Clone() HQ.Parent = workspace.Buildings for i,child in pairs(HQ:GetChildren()) do if child:IsA("BasePart") then child.Transparency = 0.5 end end ------------------------------------------------------ ------------------------------------------------------- mouse.Move:connect(function() local child = workspace.Buildings.Headquarters child:MoveTo(mouse.hit.p) end) end mouse.Button1Down:connect(function () --child:Remove() mouse.TargetFilter = HQ print (mouse.Target) if mouse.Target ~= nil and mouse.Target.Name == "Allowed1" then -- Where you can build on print "Allowed" print "Placed" for i, child2 in pairs(HQ:GetChildren()) do if child2:IsA("BasePart") then child2.Transparency = 0 local newModel = HQ:Clone() -- Clones the model to prevent it from moving newModel.Parent = game.Workspace.Buildings newModel.Name = "HQ1" workspace.Buildings.HQNumber.Value = workspace.Buildings.HQNumber.Value + 1 child2:Destroy() --This is making the script mess up I need to restart after I call this --child2.Transparency = .5 end end end end) clickdetector.MouseClick:connect (temp)
At line 75, you connect on the event of the player's mouse moving. But that function will fire every time the mouse is moved. Unless, you put an if statement within the function, to check if it's still valid to move the object.