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

Adding permissions only to specific players on this ToolGiver script?

The script works by detecting when somebody says a specific phrase, then copies a tool from ReplicatedStorage and places it in the player's backpack.

I'm trying to make a variation of it where the commands only apply to a few specific players and identifies them by their usernames. I'm unsure how that would be rigged, though. Here's a basic version of the script. I keep the tools stored in a folder called "Tools" in Replicated Storage. You can just remove ".Tools" from the script and keep them in Replicated Storage to make it easier to test, though.

I'm thinking that it should be like "if player.name = {"examplename", "examplename2",} then..." and then only gives them permission to use that command. But when I tried it on my own, it didn't work out. I'm still a novice at scripting. Below is a vanilla version of the script so it's easier for you guys to work with.

Thanks in advance to whoever knows how to solve this!

game.Players.PlayerAdded:connect(function(player) -- gets player
    player.CharacterAdded:connect(function(Character)
	--I think about here would be where permissions would be inserted. I don't know how to rig that, though.
            player.Chatted:connect(function(msg)
                local speaker = player
                print(speaker)

                if msg == '/knight' then
                    local knight1 = game.ReplicatedStorage.Tools:FindFirstChild("Sword")
                    local knight2 = game.ReplicatedStorage.Tools:FindFirstChild("Shield")
                    local knight3 = game.ReplicatedStorage.Tools:FindFirstChild("Spear")
                    knight1:Clone().Parent = speaker.Backpack
                    knight2:Clone().Parent = speaker.Backpack
                    knight3:Clone().Parent = speaker.Backpack

                elseif msg == "/archer" then
	                local archer1 = game.ReplicatedStorage.Tools:FindFirstChild("Arrow")
                    local archer2 = game.ReplicatedStorage.Tools:FindFirstChild("Dagger")
                    local archer3 = game.ReplicatedStorage.Tools:FindFirstChild("Darts")
                    archer1:Clone().Parent = speaker.Backpack
                    archer2:Clone().Parent = speaker.Backpack
                    archer3:Clone().Parent = speaker.Backpack
                end
            end)
        end)  
    end)

1 answer

✓ Accepted answer

In order to do this, you would have to put a script in ServerScriptService and put in the following:

game.Players.PlayerAdded:Connect(function(player)
	local specialplayers = {'AntoninFearless', 'SomeoneYouLike'} --Put in the usernames you want
	player.CharacterAdded:connect(function(char)
		for _,v in pairs(specialplayers) do --This gets the special players
			print(v)
			player.Chatted:connect(function(msg)
				if player.Name == v then --If the players name is one of the special players then
					if msg == '/knight' then --If the special player says /knight then
						local sword = game.ReplicatedStorage:FindFirstChild('sword')
						local gun = game.ReplicatedStorage:FindFirstChild('handgun')
						local sniper = game.ReplicatedStorage:FindFirstChild('sniper')
						gun:Clone().Parent = player.Backpack
						sword:Clone().Parent = player.Backpack
						sniper:Clone().Parent = player.Backpack
					end
				else --If they are not the special player then
					print('This is not a special player') --Nothing happens, it only just prints that they are not special :(
				end
			end)
		end
	end)
end)

This worked just fine in my studio. Hopefully, this helps you.

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