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

Is this DataStore request written properly? [closed]

Asked by
trogyssy 221 Moderation Voter
10 years ago
local Lvl=p.leaderstats.Lvl--P is a player
local Get=Game:GetService("DataStoreService"):GetDataStore("Points"):GetASync(p.Name.."Lvl")
if Get then
    Lvl.Value=Get
elseif not Get then
    Game:GetService("DataStoreService"):GetDataStore("Points"):SetASync(p.Name.."Lvl", 1)
    Lvl.Value=1
end

Thank you for your time. I'm afraid if I test it I might mess something up, seeing as it saves...

EDIT: Here's the full script. I'd be very grateful if you could read it and let me know if you see any obvious errors.

while not script.Parent.Parent.Parent.Parent.leaderstats.Lvl do wait() end

local p=script.Parent.Parent.Parent.Parent
local Lvl=p.leaderstats.Lvl
local Exp=Instance.new("IntValue")
Exp.Parent=script.Parent
Exp.Value=0

local Get=Game:GetService("DataStoreService"):GetDataStore("Points"):GetAsync(p.Name.."Lvl")
if Get then
    Lvl.Value=Get
elseif not Get then
    Game:GetService("DataStoreService"):GetDataStore("Points"):SetAsync(p.Name.."Lvl", 1)
    Lvl.Value=1
end

local Goals={50, 100, 250, 500, 750, 1000, 2500, 5000, 10000}
function Raise()
    for i, v in ipairs(Goals) do
        if Exp.Value==v then
            Game:GetService("DataStoreService"):GetDataStore("Points"):IncrementAsync(p.Name.."Lvl")
            Lvl.Value=i
            script.Parent.Bar.Size=Udim2.new(0, 0, 0, 20)
            Exp.Value=0
        end
    end
    if Exp.Value~=0 then
    script.Parent.Bar.Size=Udim2.new(0, 140/Exp.Value, 0, 20)
    end
end

while true do
wait(3)
Exp.Value=Exp.Value+1
Raise()
end
1
Try creating a separate test place to test things, like DataStore. That, and I don't believe "ASync" would be valid for setting or getting as the method only has the "A" captialized, and methods (as with most things in lua, or most programming/scripting languages) are case sensitive. User#2 0 — 10y
0
Thanks :) I just checked and it should be SetAsync, GetAsync instead trogyssy 221 — 10y

Closed as Not Constructive by User#2

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?