I watched a video on how to add currency, and now i want to add 2 currencies. I don't exactly know how.. I am very new to this if i could get some help that would be great
local currencyName = "Zimo" local DataStore = game:GetService("DataStoreService"):GetDataStore("Currency") game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local currency = Instance.new("IntValue") currency.Name = currencyName currency.Parent = folder local ID = currencyName.."-"..player.UserId local savedData = nil pcall(function() savedData = DataStore:GetAsync(ID) end) if savedData ~= nil then currency.Value = savedData print("Data Loaded") else --New player-- currency.Value = 750 print("New player to game") end end) game.Players.PlayerRemoving:Connect(function(player) local ID = currencyName.."-"..player.UserId DataStore:SetAsync(ID,player.leaderstats[currencyName].Value) end) game:BindToClose(function() -- When game is ready to shutdown for i, player in pairs(game.Players:GetPlayers()) do if player then player:Kick("Server shuting down") end end wait(5) end)
Also if there is a better way to do this im open for it.
Just use the same code you used before
local currency = Instance.new("IntValue") --- change currency to the other currency currency.Name = currencyName -- Change The Name currency.Parent = folder
If You Wanted Cash You'd Do
local Cash = Instance.new("IntValue") Cash.Name = Cash Cash.Parent = folder
The Datastore I use is
game.Players.PlayerRemoving:Connect(function(player) local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."leaderstats") local statstorage = player:FindFirstChild("leaderstats"):GetChildren() for i = 1, #statstorage do datastore:SetAsync(statstorage[i].Name, statstorage[i].Value) print("Saved Data Number ("..i..")") end print("Stats Successfully Saved!") end) game.Players.PlayerAdded:Connect(function(player) local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."leaderstats") player:WaitForChild("leaderstats") wait(1) local stats = player:FindFirstChild("leaderstats"):GetChildren() for i = 1, #stats do stats[i].Value = datastore:GetAsync(stats[i].Name) print("stats number ("..i..") has been found") end end)
Works Fairly Well