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

how do i add like a sword to my starter pack to where only certain players can get it?

how do i add like a sword to my starter pack to where only certain players can get it

2 answers

✓ Accepted answer

A PlayerAdded and CharacterAdded events are needed to do this. Script

game.Players.PlayerAdded:connect(function(plr) -- playeradded event identifying the player that joined as "plr"
    plr.CharacterAdded:connect(function(char) -- characteradded event, identifying the plr's character that respawned as "char"
	if plr.Name == "NameHere" then -- Change "NameHere" to the player that has the permission to have the tool.
           local tool = game.ServerStorage.Tool:Clone() -- cloning the tool from serverstorage, change this to your parenting
           local backpack = plr:findFirstChild("Backpack") -- getting the player's backpack
	   if backpack then -- checking if the backpack exists to prevent possible errors(not necessary)
               tool.Parent = backpack -- parenting it to their backpack.
            end
        end
    end)
end)

Full Script:

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		if plr.Name == "NameHere" then
			local tool = game.ServerStorage.Tool:Clone()
			local backpack = plr:findFirstChild("Backpack")
			if backpack then
				tool.Parent = backpack
			end
		end
	end)
end)

Hope it helped!

8 comments

0

where do i put that just in work space?

0

im confused on line 4

0

Put the tool under ServerStorage, and name it "Tool"

0

I made a mistake on line 4 because I was typing really fast and was in a hurry, but I just fixed it.

0

Ok where do I but the tool name

0

Ok where do I but the tool name

0

You replace "Tool" on line 4 with the tool name.

0

Ok where do I but the tool name


game.Players.PlayerAdded:connect(function(plr) -- playeradded event identifying the player that joined as "plr"
    plr.CharacterAdded:connect(function(char) -- characteradded event, identifying the plr's character that respawned as "char"
    if plr.Name == "ags5321" then -- Change "NameHere" to the player that has the permission to have the tool.
            local tool = game.ServerStorage:Clone("Card1") -- cloning the tool from serverstorage, change this to your parenting
            local backpack = plr:findFirstChild("Backpack") -- getting the player's backpack
        if backpack then -- checking if the backpack exists to prevent possible errors(not necessary)
                tool.Parent = backpack -- parenting it to their backpack.
        end
    end
    end)
end)

is that it

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