In this tutorial I show you how to make a currency Script. I don't do that well explaining so I will just add the explainations to the script. :) All credits go to ItsTerrarian21Playz aka Terrarian 21
local currencyname = "Money" --Name the currency
local Datastore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") --Stores The Amount
game.Players.PlayerAdded:Connect(function(player) --next few lines add the leaderboard data
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = CurrencyName --takes the name of your currency and adds it into the leaderboard
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:Async(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data Loaded") --Tells that data has loaded
else
-- If New Player Loads The Following
currency.Value = 50
print("New Player To The Game")
end
end)
game.Players.Removing:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(Id,player.leaderstats [currencyName] .Value)
end)
game:BindToClose(function()
--Starts when Server Shutsdown
for i, player in pairs (game.Players:GetPlayers()) do
if player then
player:Kick("This Server Has Started To Shutdown. Please do rejoin") --the message it gives you
end
end
wait(5) --waits 5 seconds so they can read the message then kicks them
end
--Thanks For Going Through this simple Tutorial. If you need any help, just message me on Discord (Terrarian 21#0015)
www.youtube.com/c/terrarian21
www.twitter.com/terrarian21