Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to save backpack even after resetting?

Asked by
Jirozu 71
7 years ago

I was making a script that gives you a random power once you join, here is the code:

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 = QuirksChosen:Clone()
local backpack = player:WaitForChild("Backpack")
quirk.Parent = backpack

end

Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

But everytime the player resets or dies, they lose the power. Any way i can fix that error?

0
Tip: Players>Player>StarterGear <- That is where the gears get saved TheePBHST 154 — 7y
0
OMG U MAKING A MY HERO ACA GAME!!! taunter165 30 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You can implement the CharacterAdded event into your code to make the power be added into their inventory whenever they spawn :)

Btw - the generic for loop is redundant since there are no players in your game at the start of the server.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        local Quirks = game.ServerStorage.Quirks:GetChildren()
        local RandomizeQuirks = math.random(1, #Quirks)
        local QuirksChosen = Quirks[RandomizeQuirks]
        print(QuirksChosen)
        local quirk = QuirksChosen:Clone()
        quirk.Parent = player:WaitForChild("Backpack")
    end)
end)
Ad

Answer this question