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

How do I make this script let all the player type the command instead of specific players?

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)

2 answers

✓ Accepted answer

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.

2 comments

0

Addendum, you shouldn't use Lighting to store maps in, roblox has services such as ReplicatedStorage And ServerStorage for that purpose. http://wiki.roblox.com/index.php?title=API:Class/ReplicatedStorage

0

How do i make it remove the old map and then spawn the new map?

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

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