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
8 years ago

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

01local Players = game:GetService("Players")
02 
03 
04function onPlayerAdded(player)
05 
06local Quirks = game.ServerStorage.Quirks:GetChildren()
07local RandomizeQuirks = math.random(1, #Quirks)
08local QuirksChosen = Quirks[RandomizeQuirks]
09print(QuirksChosen)
10local quirk = QuirksChosen:Clone()
11local backpack = player:WaitForChild("Backpack")
12quirk.Parent = backpack
13 
14end
15 
16Players.PlayerAdded:connect(onPlayerAdded)
17 
18for _,player in pairs(Players:GetPlayers()) do
19     onPlayerAdded(player)
20end

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 — 8y
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
8 years ago
Edited 8 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.

01game.Players.PlayerAdded:Connect(function(player)
02    player.CharacterAdded:Connect(function()
03        local Quirks = game.ServerStorage.Quirks:GetChildren()
04        local RandomizeQuirks = math.random(1, #Quirks)
05        local QuirksChosen = Quirks[RandomizeQuirks]
06        print(QuirksChosen)
07        local quirk = QuirksChosen:Clone()
08        quirk.Parent = player:WaitForChild("Backpack")
09    end)
10end)
Ad

Answer this question