Is this script right?

Basically I wanted to make a script that gives a gear when I join the game, I used a yt tutorial but didn’t work

Is this script right or something is wrong?
(I removed the user for privacy)

local players = {“user”}
local gear = game.ServerStorage.Banana

for i = 1, #players do
if players[i] == then
gear:Clone().Parent = plr Waitforchild(“backpack”)

Heya! :3

Remember to format your code with the </> button

Yup, that code from that YT tutorial its a mess :v
Add a Banana to your Inventory/Backpack when YOU join, or when any player joins?

local Players = game:GetService("Players")
local gear = game.ServerStorage.Banana

local YOU = "nikitafl"

		-- Give Banana to anyone joining the Server
		gear:Clone().Parent = plr:WaitForChild("Backpack")
		-- OR
		-- Give Banana to an User Named nikitafl
		if plr.Name == YOU then
			gear:Clone().Parent = plr:WaitForChild("Backpack")

The first one is when any player joins, the second one when You join. Delete any of those at your needs

I totally agree with @0V_ex. The only thing you should use its ID’s. And probably you want a table to store the players you want to give Banana :v
Just keep it simple if you are starting with scripting. :3

1 Like

@Dev_Peashie’s code is right, but I see you want multiple players in. I hope this helps:

local ids = {userId1, userId2, userId3, ...} -- UserId is better than Username because usernames can be changed

local gear = game:GetService("ServerStorage").Gears.Banana -- Make sure the "Banana" is in a folder called "Gears" in ServerStorage just to keep it organised

    if not table.find(ids, plr.UserId) then return end
    gear:Clone().Parent = plr.Backpack

Oops accidentally sent it ;-;


On the 4th line when there is written “ids, prl.userId”
Do I need type my id?

No, you don’t. Just fill up the UserIds in the table like so:

local ids = { 91455689, 2 } -- and so on