I have never been able to get datastores down, and i cant get it to work, everything looks fine to me…
If anyone could help me identify the problem that would be very helpful.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Clicks"
money.Value = 0
money.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserID.."-Clicks")
end)
if success then
money.Value = data
end
end)
local plr = game.Players.LocalPlayer
local button = script.Parent
local MPS = game:GetService("MarketplaceService")
local id = 8463045
game.Workspace.ClickEvent.OnServerEvent:connect(function(plr)
if MPS:UserOwnsGamePassAsync(plr.UserId, id) then
plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + 2 else
plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserID.."-Clicks",player.leaderstats.money.Value)
end)
end)