So basically, My script, you have to type the command "run/..." DotDotDot meaning the map name. Which I done. But I want the script to also remove the old map and replace it with the new map.
local current_map; game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chatmsg) if chatmsg:sub(1,4) == "run/" then local map = game.ServerStorage:FindFirstChild(chatmsg:sub(5)) local backup = map:clone() if map then if current_map then current_map.Parent = game.ServerStorage end map = backup:clone() map.Parent = workspace.Objects current_map = map end end end) end)
Are you sure this doesn't work? It worked perfectly fine when I replicated the situation in studio.
You do have a few logical mishaps, but nothing that would break the code.
You're defining backup prior to checking if the map exists. This will throw an error if you type the wrong name in. But again, wouldn't break the code.
You're parenting current_map back into ServerStorage when you cloned it in the first place. This will duplicate the object.
Go try it again. It does work. Even without these edits
local current_map; game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chatmsg) if chatmsg:sub(1,4) == "run/" then local map = game.ServerStorage:FindFirstChild(chatmsg:sub(5)) if map then if current_map then current_map:Destroy(); end map = map:Clone() map.Parent = workspace; current_map = map end end end) end)