I want the script to let all players in the server type the command spawn/MAP_NAME but I don't know how to change it so all players in the server can type the command. This script is for a singleplayer game or a one player per server game. Too make your job easier.
current_map = nil names = {"YourNameHere","AnotherPlayersName"} game.Players.PlayerAdded:connect(function(player) for i, v in pairs(names) do if v == player.Name then player.Chatted:connect(function(chatmsg) if chatmsg:sub(1,4) == "spawn/" then local map = chatmsg:sub(5, chatmsg:len()) if game.Lighting:FindFirstChild(map) then if current_map ~= nil then current_map.Parent = game.Lighting end game.Lighting[map].Parent = game.Workspace current_map = game.Workspace[map] end end end) end end end)
All you have to do is remove the for loop which checks the name of the player against the table. If you aren't using the table, you can remove that too.
local current_map; --// Usage of local variables is recommended, and you can omit the '= nil' when the value is nil. game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chatmsg) if chatmsg:sub(1,4) == "spawn/" then local map = chatmsg:sub(5, chatmsg:len()) if game.Lighting:FindFirstChild(map) then if current_map ~= nil then current_map.Parent = game.Lighting end game.Lighting[map].Parent = game.Workspace current_map = game.Workspace[map] end end end) end)
I did it for you this time, but for future reference, please properly indent your code; it makes it easier for anyone who wants to help you out to read your code, and makes it easier for you to fix any potential errors.
Hope this helped.
You simply have to remove the part where it checks the player name. Looks like you don't have much scripting knowledge so I'll do this for you.
local current_map game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chatmsg) if chatmsg:sub(1,4) == "spawn/" then local map = game.Lighting:FindFirstChild(chatmsg:sub(5)) if map then if current_map then current_map.Parent = game.Lighting end map.Parent = workspace current_map = map end end end) end)
I also did some optimization. I recommend using ServerStorage over lighting but I don't want to break your game myself lol. Later