this is my script local dataStoreService = game:GetService("DataStoreService") local clicksDatastore = dataStoreService:GetDataStore("Clicks1")
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats"
local clicks = Instance.new("IntValue",leaderstats) clicks.Name = "Clicks" clicks.Value = 0 local playerUserId = "player_"..player.UserId -- Loading Data local clicksdata local success, errormessage = pcall(function() clicksdata = clicksDatastore:GetAsync(playerUserId) end) if success then clicks.Value = clicksdata end
end)
-- saving data game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "player_"..player.UserId
local clicksValue = player.leaderstats.Clicks.value local success, errormessage = pcall(function() clicksDatastore:SetAsync(playerUserId, clicksValue) end)
end)
game:BindToClose(function(player) local playerUserId = "player_"..player.UserId
local clicksValue = player.leaderstats.clicks.value local success, errormessage = pcall(function() clicksDatastore:SetAsync(playerUserId, clicksValue) end)
end)
and this is the error ServerScriptService.leaderstats:37: attempt to index nil with 'UserId'