RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Can you write a script that adds persistent money to the server?"
Yes, I can help you with that. You'll need to use Roblox's DataStoreService to save and load the player's money data. Here's a script that you can use as a starting point: ```lua local DataStoreService = game:GetService("DataStoreService") local MoneyDataStore = DataStoreService:GetDataStore("MoneyDataStore") game.Players.PlayerAdded:Connect(function(player) local success, money = pcall(function() return MoneyDataStore:GetAsync(player.UserId) end) if success then if not money then money = 0 end else print("Error loading money data for " .. player.Name) money = 0 end local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Money = Instance.new("IntValue") Money.Name = "Money" Money.Value = money Money.Parent = leaderstats end) game.Players.PlayerRemoving:Connect(function(player) local money = player.leaderstats.Money.Value local success, err = pcall(function() MoneyDataStore:SetAsync(player.UserId, money) end) if not success then print("Error saving money data for " .. player.Name) end end) ``` This script will create a DataStore to save the player's money data. When a player joins the game, it will load their money data and create a leaderstat called "Money" to display it. When the player leaves the game, it will save their money data to the DataStore.