Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to save backpack even after resetting?

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?

2 comments

0

Tip: Players>Player>StarterGear <- That is where the gears get saved

0

OMG U MAKING A MY HERO ACA GAME!!!

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.