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

How can I code this when I join my game I get certain gear?

How would I code this when I join my game I get certain gear? Not starter pack so everyone gets it, just me . And aswell gives 2 or 3 other people gear?

game.Players.PlayerAdded:connect(function(player) if player.Name == "EnterYourNameHere" then game.Whereeveryoustoredit.thing:Clone().Parent = player end end)

1 comment

0

This isn't a request website, stop giving out false reputation to people who shouldn't get it

3 answers

I don't usually like giving out script but this one is simple to do.

I would not use the players name as you can change them which would be bad, instead use their player id.

local gear = game:GetService('ServerStorage'):WaitForChild('Gear name ect')
local plrList = { 
	-- list of player id
}

game.Players.PlayerAdded:connect(function(plr)
	local uId = plr.UserId -- the players id
	
	for i,v in pairs(plrList) do
		-- now we check the user id agains our list
		if v == uId then clnGear(plr:WaitForChild('Backpack')) break end-- the break will exit this loop
	end
	
end)

-- a simple clone function to give the gear to the player
function clnGear(plrBackpack)
	local tmp = gear:Clone() -- make a clone
	tmp.Parent = plrBackpack -- give It to the player
end

There are better ways of doing and I would not do it this way. This is only an example script, hope this helps.

The only problem is, you can't store a tool or gear in the 'player' sooo.. Behind player you add .Backpack. Sorry is code looks bad, on tablet.

game.Players.PlayerAdded:connect(function(player) 
    if player.Name == "EnterYourNameHere" then.      game.Whereeveryoustoredit.thing:Clone().Parent = player.Backpack -- Needed to add that.
    end
end)

kingdom5's answer was decent, but I think he should've used a Dictionary instead of a Table, so I wrote my own script for you. I included comments to help guide you on how it works.

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local GearToGive = ServerStorage:FindFirstChild("") -- Put the name of the gear here, and place the gear in serverstorage

--// Add the PlayerIDs of people you want to get the gear in this list:
local AllowedPlayers = {
	[70685745] = true,
	[15631081] = true,
}

--// If the backpack wasn't immediately ready, this method will wait until it is
function getBackpack(Player)
	repeat until Player.ChildAdded:wait().Name == "Backpack"
	return Player["Backpack"]
end

Players.PlayerAdded:connect(function(Player)
	if AllowedPlayers[Player.UserId] then
		Player.CharacterAdded:connect(function()
			local Backpack = Player.Backpack or getBackpack(Player) -- Get the backpack if it's ready, or wait until it is
			GearToGive:Clone().Parent = Backpack
		end)
	end
end)

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