Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Data Stores problem?

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)

3 comments

0

Are you getting any kind of output?

0

@Adark: I'm not, actually. :p

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.

1 answer

✓ Accepted answer

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!

1 comment

0

Seriously? Who downvoted this?

This discussion is preserved as it was. New answers, comments, and votes are closed.