While loop not working

I want to make it so the player gets cash every 0.5 seconds

When I join, I get the cash value once

game.Players.PlayerAdded:Connect(function(plr)
	local x = require(game.ReplicatedStorage.EternityNum)
	local s = plr:WaitForChild("Stats")
	local m = plr.Stats:FindFirstChild("Money")
	local mu = plr.Stats:FindFirstChild("Multi")
	
	while wait(0.5) do
		local svb = x.convert(mu.Value)
		local val = x.convert(1)
		local val = x.mul(val, (x.add(x.mul(x.convert(mu.Value),{1,0}),{1,0})))
		svb = x.add(svb,val)
		m.Value = x.bnumtostr(svb)
		
	end
end)


2 Likes

check the output, maybe the s variable is an infinite yield, preventing everything else from running. Did you spell “Stats” as you spelt it elsewhere?

2 Likes

It is a problem with your :WaitForChild, make sure it is the correct name.

2 Likes

Its having no problem getting the stats, the problem is its not repeating the math so for this example, I should be getting 3 money every 0.5 seconds, but I only get 3 money

2 Likes

this might be the problem, actually. It doesn’t look like you add to the variable anywhere.

1 Like

Have you read the article on while loops? Repeating Code with while Loops | Documentation - Roblox Creator Hub

I would try:

while true do
— logic
task.wait(0.5)
end
1 Like

I did the math stuff wrong, fixed it

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.