Datstore2 Problem

Ok, today I learned how to use Datstore2. I have encountered a problem though.

I want to see real time that my players data has saved. I am using a part and insert a clickdector. It fires and it should show me the value increasing each time. And it doesn’t. But when I leave the game… the values shows its update form. What is wrong?

Current Script:

local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))

local defaultValue = 0

game.Players.PlayerAdded:Connect(function(plr)
	
	local pointsDataStore = DataStore2("points",plr)
	
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue",leaderstats)
	points.Name = "Wins"
	
	local function pointsUpdate(updatedValue)
		
		points.Value = pointsDataStore:Get(updatedValue)
		
		
	end
	
	pointsUpdate(defaultValue)	
	
	pointsDataStore:OnUpdate(pointsUpdate())
	
end)

game.Workspace:WaitForChild("Part").ClickDetector.MouseClick:Connect(function(player)
	
	local pointsDataStore = DataStore2("points",player)
	
	
	pointsDataStore:Increment(50,defaultValue)
	
end)

Change that line to:

pointsDataStore:OnUpdate(pointsUpdate)

Wow, I cant believe the slightest mistake can affect the whole script like that. Thanks!

No problem! Just remember that when you’re connecting a function, don’t put those extra parentheses.

1 Like