Hi guys! I am building a game and I was trying to implement DataStore into my game. Here is my code:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Skyline") game.Players.PlayerAdded:connect(function(player) local key = "user_" .. player.userId DataStore:GetAsync(key, function(newValue) if newValue <= 49 then script.GotSkyline:Clone().Parent = player else end end) end)
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:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Skyline") local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent function OnClicked() local key = "user_" .. player.userId DataStore:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 newValue = newValue + 50 return newValue end) end script.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!