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

How To Fix Chat Activated Tool Giver?

Someone had helped me with this script yesterday, but it only targets the player who fires the command instead of the player which it is destined to target for:

local GroupID = 3248427
 
 game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message)
        if player:IsInGroup(GroupID) and player:GetRankInGroup(3248427) >= 5 then
            if message == ":give ".. player.Name .." room 101" then
                game.Players.LocalPlayer:GetChildren()
                print(player.LocalPlayer.Character.Name)
                print(player.LocalPlayer.Name)
                game.ReplicatedStorage["Room101"]:Clone().Parent = game.Workspace[player.Name]

                script.Parent.SurfaceGui.Frame.R101.BackgroundColor3 = script.Parent.SurfaceGui.Frame.R101.ColorInActive.Value 
                end
            end
        end)
 end)

1 answer

✓ Accepted answer

You would have to get all the players from the game and compare their name with the message. I hope this should work, if it doesn't or you meant something different, please say!

local GroupID = 3248427

 game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message)
        if player:IsInGroup(GroupID) and player:GetRankInGroup(3248427) >= 5 then
	   for index, plr in pairs(game.Players:GetPlayers()) do
              if message == ":give ".. plr.Name .." room 101" then
		 -- Do what you want, plr is the player!
                  game.Players.LocalPlayer:GetChildren()
                  print(player.LocalPlayer.Character.Name)
                  print(player.LocalPlayer.Name)
                  game.ReplicatedStorage["Room101"]:Clone().Parent = game.Workspace[player.Name]

                  script.Parent.SurfaceGui.Frame.R101.BackgroundColor3 = script.Parent.SurfaceGui.Frame.R101.ColorInActive.Value 
                  end
		end
            end
        end)
 end)

I hope this works for you, if you want to understand how it works I'll give a quick example

local target = 'randomPlayer' -- set up a target

for index, plr in pairs(game.Players:GetPlayers()) do -- Get all players
	if plr.Name == target then -- test if names are the same
		-- code
	end
end

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