RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make a leaderboard that saves the amount of wins when you step part"
-- script for leaderboard local players = game:GetService("Players") local dataStore = game:GetService("DataStoreService"):GetDataStore("WinsData") local function onPlayerAdded(player) local wins = Instance.new("IntValue") wins.Name = "Wins" wins.Parent = player local savedWins local success, err = pcall(function() savedWins = dataStore:GetAsync(player.UserId .. "-Wins") end) if success and savedWins then wins.Value = savedWins else wins.Value = 0 end end local function onPlayerRemoving(player) local wins = player.Wins.Value local success, err = pcall(function() dataStore:SetAsync(player.UserId .. "-Wins", wins) end) if not success then warn("Error saving wins for player: " .. player.Name) end end players.PlayerAdded:Connect(onPlayerAdded) players.PlayerRemoving:Connect(onPlayerRemoving) for _, player in ipairs(players:GetPlayers()) do onPlayerAdded(player) end -- script for part local part = script.Parent local function onTouched(otherPart) local player = game.Players:FindFirstChild(otherPart.Parent.Name) if player then player.Wins.Value = player.Wins.Value + 1 end end part.Touched:Connect(onTouched)