Model not changing parents when using a chat command

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    use chat commands to change the location of a part of the map.
  2. What is the issue? Include screenshots / videos if possible!
    the model will not go to workspace or serverstorage.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    changed game.(LOCATION) to script.parent for the model
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
if plr.name == "FriendlyName" then
if msg == "run" then
  script.Parent.Parent = game.Workspace
elseif msg == "end" then
script.Parent.Parent = game.ServerStorage
          end
       end
    end)
end)
1 Like

Hey,

I think the issue here is that scripts don’t run if they’re inside ServerStorage, so if you were to say the message while the brick was in ServerStorage it wouldn’t do anything. I would personally put the script in somewhere like ServerScriptService. In the first line of the script you could create a variable that references the part.

I’ve modified your script to something that should work if you use the setup above.

local Part = game.ServerStorage.PartName

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        if plr.name == "FriendlyName" then
            if msg == "run" then
               Part.Parent = game.Workspace
            elseif msg == "end" then
                Part.Parent = game.ServerStorage
            end
       end
    end)
end)

Edit: Sorry for updating my reply. I’ve changed the code to something a bit cleaner but the previous version will work also.

2 Likes