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

Why won't my backpack script update the players gear after they level up?

Asked by 9 years ago

I posted a question earlier about making items appear in the backpack every time a player respawns, and I solved that problem. Now, whenever a player joins, it doesn't give them any gear items until after they respawn. Also, once they level up, it doesn't update their gear, so they are always stuck with the same level gear that they started with. I don't really know how to fix this problem, and need some help!

(This is just a piece of the larger script)

01game.Players.PlayerAdded:connect(function(player)
02 
03local lev0 = false
04local lev1 = false
05 
06    while true do
07        local statstore = game:GetService("DataStoreService"):GetDataStore("levels")
08        key = "user_" .. player.userId
09        local stats = statstore:GetAsync(key)
10 
11        if stats >= 0 and lev0 == false then
12            local flashlight = game.ServerStorage.Flashlight:Clone()
13            flashlight.Parent = player.Backpack
14            flashlight.Parent = player.StarterGear
15            lev0 = true
View all 23 lines...
0
First thing would be to add a wait value. deputychicken 226 — 9y
0
Where? Legobrain9275 25 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago
01game.Players.PlayerAdded:connect(function(player)
02 
03local lev0 = false
04local lev1 = false
05 
06    local players = {}
07    for a,b in pairs(game.Players:GetChildren()) do
08            table.insert(players,b)
09    end
10    for i=1, #players do
11            local statstore = game:GetService("DataStoreService"):GetDataStore("levels")
12            key = "user_" .. player.userId
13            local stats = statstore:GetAsync(key)
14 
15            if stats >= 0 and lev0 == false then
View all 25 lines...

This should work.

Ad
Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

For level 0 you are checking if the value stats is greater than or equal to 0 meaning even if it's level 1 it will still be greater than 0 so it will still count that as level 0 and level 1, so use == not >=

0
That is how I wanted it to be set up, so that you get the rewards from every level equal to and below your current level Legobrain9275 25 — 9y

Answer this question