The only way to get the code after the while loop is to have some kind of breakout aka:
local doBreak = false
while true do
if(doBreak == true) then
break
end
wait()
end
print("hello world!")
to make it easyer i would make changes from:
local Player = game.Players.LocalPlayer
local AmountOfCash
function CheckStats()
if Player then
local Cash = Player.leaderstats.Cash.Value
return Cash
end
end
while wait() do
local cash = CheckStats()
AmountOfCash = cash
end
Player.leaderstats.Cash.Changed:Connect(function(amount)
local number = CheckStats()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modula = require(game.ReplicatedStorage.AbbreviateNumber)
local text = Modula:Abbre(number)
script.Parent.Cash.Text = text
print(amount - AmountOfCash)
end)
To:
local Player = game.Players.LocalPlayer
local AmountOfCash
function CheckStats()
if Player then
local Cash = Player.leaderstats.Cash.Value
return Cash
end
end
Player.leaderstats.Cash.Changed:Connect(function(amount)
local number = CheckStats()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modula = require(game.ReplicatedStorage.AbbreviateNumber)
local text = Modula:Abbre(number)
script.Parent.Cash.Text = text
print(amount - AmountOfCash)
end)
while wait() do
local cash = CheckStats()
AmountOfCash = cash
end
for the code you posted to work after the while loop you would need some way of breaking out of the loop but then re-call the loop after you hook up the event for your cash.
something like:...
local Player = game.Players.LocalPlayer
local AmountOfCash
function CheckStats()
if Player then
local Cash = Player.leaderstats.Cash.Value
return Cash
end
end
local FinishedLoading = false
function mainLoop()
while wait() do
local cash = CheckStats()
AmountOfCash = cash
if(FinishedLoading == false) then
break;
end
end
end
mainLoop()
Player.leaderstats.Cash.Changed:Connect(function(amount)
local number = CheckStats()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modula = require(game.ReplicatedStorage.AbbreviateNumber)
local text = Modula:Abbre(number)
script.Parent.Cash.Text = text
print(amount - AmountOfCash)
end)
FinishedLoading = true
mainLoop()
4 comments
When would you want to stop while wait() do? I need the answer so I'd know and be able to help you.
any type of loop yelds code, anything after it don't runs untill the loop stops, you can move lines 18-28 to before the loop and it will work
i dont think you get what a shoutout is
You realise your getting downvoted BECAUSE your being rude..? I don't get why you have to "shoutout" them in your title. It makes you look like a butthole.