So I have a script that uses DataStore2 to add 50 coins to a player, and, when the value is updated, set the leaderstats value to that, but it gives the error, ServerScriptService.MainServer:64: attempt to call a Instance value
I don’t know why it’s erroring, as it’s what the API documentation says for how to reference this.
Here’s the game’s code:
game.Players.PlayerAdded:Connect(function(player)
local playerDataStore = DS2("playerData",player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
local function update(updatedValue)
coins.Value = playerDataStore:Get(updatedValue)
end
playerDataStore:OnUpdate(update)
coins.Parent = leaderstats
end)
game.Workspace:WaitForChild("CoinsPart").ClickDetector.MouseClick:Connect(function(player)
local playerDataStore = DS2("playerData",player)
playerDataStore:Increment(50)
end)