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

How to make give script that gives the player a tool also work on others??

-- This is the first character we want to check messages for.

local AdminSignalCharacter = ":"

local Weapons = game.ServerStorage.Weapons
 
-- AdminCommands is a table that maps strings to functions. The string is the command name, the function is that of the command to be executed.
local AdminCommands = {
    give = function(Player, WeaponName)
    if not Weapons:FindFirstChild(WeaponName) then
        return
        end
 
        local WeaponClone = Weapons[WeaponName]:Clone()
        WeaponClone.Parent = Player:WaitForChild("Backpack")
    end
}
 
game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(Message)
        if Message:sub(1, 1) ~= AdminSignalCharacter then
            return
    end
 
        -- Get the substring not including the signal character.
        local CommandMessage = Message:sub(2)

    local Command = nil
        local Arguments = {}

    -- Match one or more word characters in a generic for loop.
        for Match in CommandMessage:gmatch("%w+") do
            if Command then
                -- We already know what command we're using, so it's an argument to it.
                table.insert(Arguments, Match)
            else
            -- If we don't already know the command, this must be the first match.
                Command = Match:lower()
            end
        end

        -- If there were no matches.
        if not Command then
            return
        end

local CommandExecutor = AdminCommands[Command]

-- If the command doesn't exist. if not CommandExecutor then return end

-- Call the function in AdminCommands.

CommandExecutor(Player, unpack(Arguments)) end) end)``

How can i adjust the script so i also type the player's name whose backpack it goes to. Thanks.

2 answers

This is not a request site. You must make a reasonable effort to solve your own problems. Posting my code from the last answer does not count as a reasonable effort.

3 comments

0

chill out dude u never helped me that much

0

This is not a request site, it is to get help with you writing your own code. Stop making requests.

Simple.

First get the table of all players.

game.Players:GetPlayers()

Now, every player is listed there.

But you also need it to update itself.

game.Players.PlayerAdded:Connect(function(player)

if not player then repeat wait() until game.Players.LocalPlayer end

players = game.Players:GetPlayers()

end)

Now the list adds the new players that come into the server too.

Next we need to go inside the list so we get the players.

If you don't know what I'm about to do don't worry:

function getNames()

local names = {}

for i,v in pairs(players) do

names[i] = v.Name

end

return names

end

Names = getNames()

Now you have all the names of players and the list self-updates.

print(unpack(Names)) -- to check what you've got.

Here you would use string pattern to check whether what the player has wrote matches a name in the player list, if it does give that player the tool into their backpack such as the cloned ones from Server Storage.

As in, (example1)

function getBackpack()

if game.Players.LocalPlayer.Name == unpack(Names) then

local BP = game.Players.LocalPlayer.Backpack

return BP

end

BackPack = getBackpack()

After that you would go into Chat Service. I would also not recommend using anybody else's script other than guidance. Only professional scripters know what they are doing and where improvement can be made. Modifying a script destroys that guidance for the client, which is why we encourage you to create your own scripts.

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