Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to make it not clone but move it to workspace? (ANSWERED)

Asked by 9 years ago

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)

1
Why are using the same event in two separate instances? DigitalVeer 1473 — 9y
0
Because It works CjGamer1454 0 — 9y
0
I updated my answer. adark 5487 — 9y
0
So what if it works? That is highly confusing and inefficient and just non paradigm-like. DigitalVeer 1473 — 9y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

0
Sorry It didn't fix the problem :/ CjGamer1454 0 — 9y
0
Thank you. CjGamer1454 0 — 9y
0
How bout If I want it with message? CjGamer1454 0 — 9y
0
You use `Instance.new("Message")` to create it, and then you simply set its `Parent` and `Text` properties. adark 5487 — 9y
Ad

Answer this question