RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make a leaderboard that saves the amount of wins when you step part"
-- server script for leaderboard (ServerScriptService) local DataStoreService = game:GetService("DataStoreService") local WinsDataStore = DataStoreService:GetDataStore("WinsData") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local wins = Instance.new("IntValue") wins.Name = "Wins" wins.Parent = leaderstats local data local success, err = pcall(function() data = WinsDataStore:GetAsync(player.UserId) end) if success and data then wins.Value = data else wins.Value = 0 end end) game.Players.PlayerRemoving:Connect(function(player) local wins = player.leaderstats.Wins.Value local success, err = pcall(function() WinsDataStore:SetAsync(player.UserId, wins) end) if not success then warn("Failed to save wins for player: " .. player.Name) end end) -- server script for part (Workspace) local part = script.Parent local function onTouched(otherPart) local player = game.Players:FindFirstChild(otherPart.Parent.Name) if player then player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1 end end part.Touched:Connect(onTouched)