local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local DataStore2 = require(ServerScriptService.DataStore2)
-- Combine every key you use. This will eventually be the default, but for now read the "Gotchas" section to understand why we need this.
DataStore2.Combine("DATA", "Clicks")
Players.PlayerAdded:Connect(function(player)
local clicksStore = DataStore2("Clicks", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local clicks = Instance.new("NumberValue")
clicks.Name = "Clicks"
clicks.Value = clicksStore:Get(0) -- The "0" means that by default, they'll have 0 points
clicks.Parent = leaderstats
clicksStore:OnUpdate(function(newPoints)
-- This function runs every time the value inside the data store changes.
clicks.Value = newPoints
end)
leaderstats.Parent = player
end)
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(ServerScriptService.DataStore2)
game.Players.PlayerAdded:Connect(function(player)
wait(1)
local clicksStore = DataStore2("Clicks", player)
clicksStore:Increment(1) -- Give them 1 point
end)
attempt to perform arithmetic (add) on nil and number
clicksStore:Increment(1) – Give them 1 point