What is wrong with my DataStore script?
Hi guys! I am building a game and I was trying to implement DataStore into my game. Here is my code:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "Skyline" ) |
03 | game.Players.PlayerAdded:connect( function (player) |
04 | local key = "user_" .. player.userId |
06 | DataStore:GetAsync(key, function (newValue) |
10 | script.GotSkyline:Clone().Parent = player |
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:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "Skyline" ) |
02 | local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent |
06 | local key = "user_" .. player.userId |
07 | DataStore:UpdateAsync(key, function (oldValue) |
08 | local newValue = oldValue or 0 |
09 | newValue = newValue + 50 |
15 | script.Parent.MouseButton 1 Click: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!