im new to scripting and ive tried to fix the script and watch youtube videos to learn what i did wrong but i cant figure it out.
local datastoreservice = game:GetService("DataStoreService") local clicksDataStore = datastoreservice:GetDataService("clicks") 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)
this is the part that isn't working and I dont know why.
--Created by : MarkHunHMD --Put in your ServerScriptService and make a SIMPLE leaderstats script
local dataStoreService = game:GetService("DataStoreService") local leaderstatsDataStore = dataStoreService:GetGlobalDataStore("leaderstats")
local loaded = {}
game.Players.PlayerAdded:connect(function(player) local leaderstats = player:WaitForChild("leaderstats")--Your leaderstats name if player.UserId > 0 and player.Parent then local leaderstatsData = leaderstatsDataStore:GetAsync(player.UserId) if leaderstatsData ~= "Request rejected" then if leaderstatsData then for i, stat in ipairs(leaderstats:GetChildren()) do local value = leaderstatsData[stat.Name] if value then stat.Value = value end end end loaded[player] = true end end end)
game.Players.PlayerRemoving:connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then if loaded[player] then local leaderstatsData = {} for i, stat in ipairs(leaderstats:GetChildren()) do leaderstatsData[stat.Name] = stat.Value end leaderstatsDataStore:SetAsync(player.UserId, leaderstatsData) end else Instance.new("Folder", player).Name = "leaderstats" end loaded[player] = nil end)