Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

? Help on Cash for different Rank.

Hello there, I am trying to make a Cash for a different Rank in my game. This is my script in ServerScriptService:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)

local fol = Instance.new("Folder", plr)
fol.Name = "leaderstats"

local Cash = Instance.new("IntValue", fol)
Cash.Name = "Yuan"
Cash.Value = 5

local Rank = Instance.new("StringValue", fol)
Rank.Name = "Rank"
Rank.Value = "Frail"

while true do
	wait(100)
	Cash.Value = Cash.Value + 1
end

while true do
if Cash.Value == 500 then
	Rank.Value = "Loark"
		wait(1)
	end
end

end)

Any suggestions are open. Thank you and stay safe.

4 comments

0

I don't understand what you want? Please be more descriptive in your questions so others and I can understand your problem

0

It's not that hard to figure out if you read the code:P

0

From my perspective I'm slightly confused on what this person wants to achieve

0

Well, when a player gets enough money, their rank changes in the game.

2 answers

Your loop isn't asynchronous, therefore your main thread will yield at increasing the Cash value indefinitely.

Threading is an option, but there is a much more efficient approach to this:

--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")



--###----------[[FUNCTIONS]]----------###--
local function InstantiateLeaderstats(Player)
	local Leaderstats = Instance.new("Folder")
	---------------
	local Rank = Instance.new("StringValue")
	local Cash = Instance.new("IntValue")
	---------------
	Leaderstats.Name = "leaderstats"
	---------------
	Rank.Name = "Rank"
	Rank.Value = "Frail"
	---------------
	Cash.Name = "Yuan"
	Cash.Value = 350
	---------------
	Rank.Parent = Leaderstats
	Cash.Parent = Leaderstats
	---------------
	Leaderstats.Parent = Player
	---------------
	return Leaderstats
end


local function OnPlayerEntered(Player)
	local Leaderstats = InstantiateLeaderstats(Player)
	---------------
	local Cash = Leaderstats.Yuan
	local CashUpdated;
	---------------
	CashUpdated = Cash:GetPropertyChangedSignal("Value"):Connect(function()
		---------------
		if (Cash.Value == 500) then
			---------------
			Leaderstats.Rank.Value = "Loark"
			---------------
			CashUpdated:Disconnect()
		end
	end)
	---------------
	while (true) do
		wait(100)
		---------------
		Cash.Value += 1
	end
end



--###----------[[SETUP]]----------###--
Players.PlayerAdded:Connect(OnPlayerEntered)

1 comment

0

This did not work though but that thanks for trying to answer!

It still did not work, though thanks for trying to answer my problem!

6 comments

0

What are you on about?

0

I had a few small errors in my code. I'm surprised you weren't able to fix them. This is proof that it works....

0

I had no errors and it did not work for me, I am sorry if you are mad about you script not working.

0

You need to use a Server-sided Script located within ServerScriptService.

0

I know that, that is the only way leaderstats work. But I think I found my error I will fix it later on when I get back in Studio.

This discussion is preserved as it was. New answers, comments, and votes are closed.