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
game.Players.PlayerAdded:Connect(function(plr)
plr.characteradded:connect(chr)
for i = 1, #players do
if players[i] == plr.name then
gear:Clone().Parent = plr Waitforchild(“backpack”)
end
end
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"
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
-- 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")
end
end)
end)
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
@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
game:GetService("Players").PlayerAdded:Connect(function(plr)
if not table.find(ids, plr.UserId) then return end
gear:Clone().Parent = plr.Backpack
end)