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

What is wrong with my DataStore script?

Asked by 11 years ago

Hi guys! I am building a game and I was trying to implement DataStore into my game. Here is my code:

01local DataStore = game:GetService("DataStoreService"):GetDataStore("Skyline")
02 
03game.Players.PlayerAdded:connect(function(player)
04    local key = "user_" .. player.userId
05 
06    DataStore:GetAsync(key, function(newValue)
07 
08        if newValue <= 49
09            then
10            script.GotSkyline:Clone().Parent = player
11            else
12        end
13    end)
14end)

In the "lobby" of my universe there is a script that gives you 50 "Skyline" or whatever when you click the purchase button in the lobby. Here is that script:

01local DataStore = game:GetService("DataStoreService"):GetDataStore("Skyline")
02local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
03 
04function OnClicked()
05 
06    local key = "user_" .. player.userId
07    DataStore:UpdateAsync(key, function(oldValue)
08        local newValue = oldValue or 0
09        newValue = newValue + 50
10        return newValue
11    end)
12end
13 
14 
15script.Parent.MouseButton1Click:connect(OnClicked)

I got that script straight from the wiki.

If someone could please help me figure out what is wrong, I would appreciate it! Thanks!

Answer this question