Hey, I am new to scripting and I have been toying around with some stuff, I created a simple cash system using tools and leaderstats, just looking for feedback on it and maybe some improvements. (not stuff to add, how to improve the script in efficiency and such):
local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local Cash = leaderstats:WaitForChild("Cash")
local player = game.Players.LocalPlayer
local CashGUI = player.PlayerGui.CashGUI
local CashLabel = CashGUI.CashLabel
local cashAmount = Cash.Value
-- Update cash display
local function formatCash(cashAmount)
if cashAmount >= 1e27 then
return string.format("%.2fOc", cashAmount / 1e27)
elseif cashAmount >= 1e24 then
return string.format("%.2fSp", cashAmount / 1e24)
elseif cashAmount >= 1e21 then
return string.format("%.2fSx", cashAmount / 1e21)
elseif cashAmount >= 1e18 then
return string.format("%.2fQi", cashAmount / 1e18)
elseif cashAmount >= 1e15 then
return string.format("%.2fQa", cashAmount / 1e15)
elseif cashAmount >= 1e12 then
return string.format("%.2fT", cashAmount / 1e12)
elseif cashAmount >= 1e9 then
return string.format("%.2fB", cashAmount / 1e9)
elseif cashAmount >= 1e6 then
return string.format("%.2fM", cashAmount / 1e6)
elseif cashAmount >= 1e3 then
return string.format("%.2fK", cashAmount / 1e3)
else
return tostring(cashAmount)
end
end
local formattedAmount = formatCash(cashAmount)
local cashPrefix = "$"
task.spawn(function()
while true do
task.wait(0.1)
CashLabel.Text = cashPrefix..formatCash(cashAmount)
end
end)
local StarterPack = game:GetService("StarterPack")
local giveCash
-- Cash Tool Variables:
local lowCash = StarterPack.lowCash
local highCash = StarterPack.highCash
local insaneCash = StarterPack.insaneCash
local superCash = StarterPack.superCash
local wtfCash = StarterPack.wtfCash
-- Cash Tool Setup:
local function setup(char)
char.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
if child.Name == "cashResetter" then
cashAmount = 0
Cash.Value = 0
end
local function cashGiver(name, amount)
if child.Name == name then
while task.wait(0.1) do
cashAmount += amount
Cash.Value += amount
end
end
end
print("Equipped", child.Name)
giveCash = task.spawn(function()
cashGiver(lowCash.Name, 150)
cashGiver(highCash.Name, 3.25e3)
cashGiver(insaneCash.Name, 12.5e3)
cashGiver(superCash.Name, 5.25e7)
cashGiver(wtfCash.Name, 725e12)
end)
end
end)
char.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
print("Unequipped", child.Name)
task.cancel(giveCash)
end
end)
end
player.CharacterAdded:Connect(setup)
if player.Character then
setup(player.Character)
end
I also provided a video to show what it actually does.