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

Help with Data Stores?

Asked by
novipak 70
10 years ago

Mmk, I have been trying to save things using Data Stores. I made a brick that adds 1 point onto the points value which works fine but when I leave the game I get this error I get:

20:50:27.569 - Value is not a valid member of GlobalDataStore

Here is the code I have for my Leaderboard:

local levl = game:GetService('DataStoreService'):GetDataStore('Level') 
local EXP = game:GetService('DataStoreService'):GetDataStore('Experience')
local mon = game:GetService('DataStoreService'):GetDataStore('Money')
local pnts = game:GetService('DataStoreService'):GetDataStore('Points')
function load1(plr)  --loads players credits
    return levl:GetAsync(plr.userId) or levl:SetAsync(plr.userId, 1) and 0
end

function load2(plr)  --loads exp function will either set or gets them from last time
    return EXP:GetAsync(plr.userId) or EXP:SetAsync(plr.userId, 0) and 0
end

function load3(plr)  --loads exp function will either set or gets them from last time
    return mon:GetAsync(plr.userId) or mon:SetAsync(plr.userId, 0) and 0
end

function load4(plr)  --loads exp function will either set or gets them from last time
    return pnts:GetAsync(plr.userId) or pnts:SetAsync(plr.userId, 0) and 0
end

game.Players.PlayerAdded:connect(function(plr)  --player joins
    local ls = Instance.new("IntValue",plr)
    ls.Name = "leaderstats"
    local lvl = Instance.new('IntValue', ls)
    lvl.Name = 'Level' 
    lvl.Value = load1(plr) --changes the value from the load function
    local xp = Instance.new('IntValue', ls)
    xp.Name = 'Experience'
    xp.Value = load2(plr)
    local money = Instance.new("IntValue", ls)
    money.Name = 'Money'
    money.Value = load3(plr)
    local points = Instance.new("IntValue", ls)
    points.Name = 'Points'  --changes the value from the load function
    points.Value = load4(plr)
end)

game.Players.PlayerRemoving:connect(function(plr)  --saves it when player leaves
    levl:UpdateAsync(plr.userId, function() return levl.Value end)
    EXP:UpdateAsync(plr.userId, function() return EXP.Value end)
    mon:UpdateAsync(plr.userId, function() return mon.Value end)
    pnts:UpdateAsync(plr.userId, function() return pnts.Value end)
end)

And, just in case it's needed, here is the code that's in the brick:

script.Parent.Touched:connect(function(hit)
    humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        player = game.Players:GetPlayerFromCharacter(hit.Parent)
        points = player.leaderstats.Points
        points.Value = points.Value + 1
    end     
end)

1 answer

Log in to vote
1
Answered by
l0cky2013 135
10 years ago

Value is not a property of a Data Store key. You might want to return the level value in the player's leaderstats.

Example

    levl:UpdateAsync(plr.userId, function() return plr.leaderstats.Level.Value end)

And do that with every one?

0
Yes! This worked! Thank you so much, this was incredibly helpful. I'm very happy :) novipak 70 — 10y
Ad

Answer this question