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

Why won't this script save player data?

Asked by
Nogalo 148
7 years ago
Edited 7 years ago

So i've made this script that's suppose to remember how many stages the player has completed and how many trophies he's collected but it won't work even tho it doesn't show any errors.If any1 has any ideas or suggestions i'm all ears.

Thanks for your time

data = game:GetService('DataStoreService'):GetDataStore('MobbyProgres')

game.Players.PlayerAdded:connect(function(p) -- Player joins

local stats = Instance.new ("IntValue",p)
    stats.Name = "leaderstats"

    local stage = Instance.new("IntValue", stats)
    stage.Name = "Stage"
    stage.Value = 1

    local trophies = Instance.new("IntValue",stats)
    trophies.Name = "TrophiesFound"
    trophies.Value = 0

    key = 'Pinfo_'..p.userId 


    if data:GetAsync(key) ~= nil then 

        stage.Value = data:GetAsync(key)[1]
        trophies.Value = data:GetAsync(key)[2]  

    else 
        data:SetAsync(key, {1,0}) 

    end
end)

game.Players.PlayerRemoving:connect(function(p) 
    key = 'Pinfo_'..p.userId 
    local save = {p.leaderstats.stage.Value, p.leaderstats.trophies.Value}
    data:SetAsync(key, save) 
end)
0
that made 0 difference Nogalo 148 — 7y
0
I've found the error thank you all for your trouble Nogalo 148 — 7y

1 answer

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago

You name your values "Stage" and "TrophiesFound", but you attempt to save "stage" and "throphies".

Fun fact: You did get errors, but you didn't see them cause it errors the moment you leave.

0
yes i figured it out but so did you so you get an accepted answer from me Nogalo 148 — 7y
0
Heh, thanks :) RubenKan 3615 — 7y
Ad

Answer this question