Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
130363 67
7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

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.

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 Pyrondon 2089 — 7y
0
How do i make it remove the old map and then spawn the new map? 130363 67 — 7y
Ad
Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 years ago

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

Answer this question