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

Data Stores problem?

Asked by
Supint 60
9 years ago

I originally took this to ROBLOX's SH but no-one's suggestions seemed to help.

What I am trying to do is create a player level which currently increments when you click script.Parent, a brick with a ClickDetector.

Also, it works in Solo Mode. Nothing else.

local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerLevel")

wait(10)--Too lazy to check for character properly 

script.Parent.ClickDetector.MouseClick:connect(function(plr)    
    local key = "user_"..plr.userId
    local gui = plr.PlayerGui.MainUI.plrLevelGui.PlrLvlNum
    datastore:IncrementAsync(key, 1)
    gui.Text = datastore:GetAsync(key)
end)
0
Are you getting any kind of output? adark 5487 — 9y
0
@Adark: I'm not, actually. :p Supint 60 — 9y
0
Don't get lazy when coding. The more lines you have and the more things you check for then the more efficient and unbreakable your code is. Tkdriverx 514 — 9y

1 answer

Log in to vote
3
Answered by 9 years ago

Here's how the wiki demonstrates use of IncrementAsync.

local number = DataStore:IncrementAsync(key, 1)

That would increase the DataStore's value by one, and also return the value of the new value, since GetAsync doesn't yield immediately after IncrementAsync is used. Here's a fixed version of your script:

local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerLevel")

wait(10)

script.Parent.ClickDetector.MouseClick:connect(function(plr)
local key = "user_"..plr.userId
local gui = plr.PlayerGui.MainUI.plrLevelGui.PlrLvlNum
local newValue = datastore:IncrementAsync(key, 1)
gui.Text = tostring(newValue)
end)

This was taken from the wiki and edited to fit your needs. If there's any problems, comment. If this works, upvote!

0
Seriously? Who downvoted this? bobafett3544 198 — 9y
Ad

Answer this question