Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

4 comments

1

Why are using the same event in two separate instances?

0

Because It works

0

I updated my answer.

0

So what if it works? That is highly confusing and inefficient and just non paradigm-like.

1 answer

✓ Accepted answer

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.

4 comments

0

Sorry It didn't fix the problem :/

0

Thank you.

0

How bout If I want it with message?

0

You use Instance.new("Message") to create it, and then you simply set its Parent and Text properties.

This discussion is preserved as it was. New answers, comments, and votes are closed.