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

How would I give tools to certain people I trust?[closed]

I placed my tool in serverstorage, and now want to clone it to the players backpack. My problem is that I only want it to clone to the backpacks of the people Who are trusted.

local trusted = {} --Player name here

I only want the tool to be given to the players in that list.

How would I do this?

local Trusted = {"PlayerNameHere"}

function GiveBtools(str, player)
	for i=1, #Trusted do
		local OwnerTools = game.ServerStorage["Building Tools"]:Clone()
		OwnerTools.Parent = player.Character.Backpack
	end
end

Updated code: Still won't work

local Owners = {"Player1"}

function GiveBtools(str, player)
	for i=1, #Owners do
		if player.Name == Owners[i] then
			local BTools = game.ReplicatedStorage["Building Tools"]:Clone()
			BTools.Parent = player.StarterGear
		end
	end
end

4 answers

Use the PlayerAdded event and check the name of the player on entry.

ex:

local players = game.Players
local trusted = {}

players.PlayerAdded:connect(function(player)
	for i,v in pairs(trusted) do
		if v == player.Name then
			-- your code here
			break
		end
	end
end)
local trusted = {
	["PlayerName1"] = true,
	["PlayerName2"] = true
}

game.Players.PlayerAdded:connect(function(p) -- when a player joins
	if trusted[p.Name] then -- searches in the trusted table for the player's name
		local c = game.ReplicatedStorage.Tool:Clone() -- clones the tool
		c.Parent = p.StarterGear --parents it in StarterGear so it doesn't disappear on death
	end
end)

Hope I helped :)

http://wiki.roblox.com/index.php?title=Table

http://wiki.roblox.com/index.php?title=API:Class/StarterGear

You'll need to loop through the table to find if the new Player is in that table. Working on the assumption that you'll know how to implement this (and I would advise something simpler than tables if you don't), you'll need a loop that looks a bit like

local isTrusted = false;
for k,v in next, trusted do
	if v == player.Name then
		isTrusted = true;
		break;
	end
end
-- if isTrusted then ...

An alternative is to use the Player names as keys, which will look a bit like

trusted = {
	PlayerName = true;
	OtherPlayerName = true
}

To check against something using that, you can simply do

if trusted[player.Name] then
	-- ...
end

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