Instead of cloning it to workspace how do I make it move to workspace?
admin = {"Player",} game.Players.PlayerAdded:connect(function(nP) for _,v in pairs(admin) do if nP.Name == v then nP.Chatted:connect(function(msg) if msg == "lockgate" then x = game.Lighting.GF:Clone() M = Instance.new("Message") M.Parent = game.Workspace x.Parent = game.Workspace wait(3) M:Remove() end end) end end end) game.Players.PlayerAdded:connect(function(nP) for _,v in pairs(admin) do if nP.Name == v then nP.Chatted:connect(function(msg) if msg == "unlockgate" then M = Instance.new("Message") M.Parent = game.Workspace game.Workspace.GF:Remove() M:remove() wait(3) end end) end end end)
First of all, it is incredibly bad practice to double the event structure like that. Instead, use an elseif
structure within the one you already have:
admin = {"Player",} game.Players.PlayerAdded:connect(function(nP) for _,v in pairs(admin) do if nP.Name == v then nP.Chatted:connect(function(msg) if msg == "lockgate" then --Since you never did anything with the Message you created, I removed it from your code. if game.Lighting:FindFirstChild("GF") then --If the gate isn't there, we will run into an error on the next line. game.Lighting.GF.Parent = game.Workspace end elseif msg == "unlockgate" then if game.Workspace:FindFirstChild("GF") then --Same as above. game.Workspace.GF.Parent = game.Lighting --It's a much better idea to have this in ReplicatedStorage, but it is not strictly necessary. end end end) end end end)
I believe the problem you were running into was that you were trying to move the parent of a non-existent object. That is, your script errors when trying to move the object if you've called the commands in the wrong order.