The script doesnt find the player's backpack in enough time to give the player their power!, here is the script:
local Players = game:GetService("Players") function onPlayerAdded(player) local Quirks = game.ServerStorage.Quirks:GetChildren() local RandomizeQuirks = math.random(1, #Quirks) local QuirksChosen = Quirks[RandomizeQuirks] print(QuirksChosen) local quirk = game.ServerStorage.Quirks:FindFirstChild(QuirksChosen.Name):clone() repeat wait() until Players.Backpack or Players.Backpack.Parent quirk.Parent = Players.BackPack end Players.PlayerAdded:connect(onPlayerAdded) for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
Any help?
Your parameter for the PlayerAdded
function is 'player', and you're using the globally defined variable 'Players'.
Keep track of your variables.
Also, when you find the randomized quirk, you already have referenced the object. There's no point in searching for it again on line 10.
Another thing, on line 13 you're indexing "BackPack". The 'P' should not be capitalized.
local Players = game:GetService("Players") local Quirks = game.ServerStorage.Quirks --^You use it multiple times, so make it a variable function onPlayerAdded(player) local CurrentQuirks = Quirks:GetChildren() local QuirkChosen = Quirks[math.random(1, #CurrentQuirks)] print(QuirkChosen) local quirk = QuirkChosen:Clone() local backpack = player:WaitForChild("Backpack") quirk.Parent = backpack end Players.PlayerAdded:connect(onPlayerAdded) for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end