If statement not working?

Hello! So I am working on a skip cutscene button and its not working? It will not print the message even though its the right amount.

script and not a localscript:

local Debouce3 = false
local Debouce4 = false
local TotalPlayers = #game:GetService("Players"):GetPlayers()

script.Parent.Parent.SkipButton.MouseButton1Click:Connect(function()
	if Debouce3 == false then
		Debouce3 = true
		script.Parent.Parent.Skips.Value = script.Parent.Parent.Skips.Value + 1
	end
end)

while wait(0.1) do
	script.Parent.Parent.SkipButton.Text = "Skips("..script.Parent.Parent.Skips.Value.."/"..TotalPlayers..")"
	if script.Parent.Parent.Skips.Value == TotalPlayers then
		print("works")
	end
end

Try printing out TotalPlayers, it’s probably going to be 0

did it and it says 1 since I joined?

Wb printing script.Parent.Parent.Skips.Value ?

Maybe put the TotalPlayers variable in the while wait(.1) do loop.

1 Like

the value changes to 1 and prints it too

then it works…?

it doesnt do anything. its like it ignores the script part

1 Like

i added a print in the while wait and it prints it but the if script doesnt work?

have you printed both totalplayers and the skips value? or just one? i’m a little confused on what is printing one here

I’ve printed both and they both seem to work. just the if statement isnt running

Are you printing both in the if statement or no? Also, why do you have two debounce variables?

no in the button mouse1buttonclicked

you aren’t updating the variable…

you should update the variable and maybe inside the loop:

local Players = game:GetService("Players")
local TotalPlayers = #Players:GetPlayers()

while task.wait(0.1) do
	TotalPlayers = #Players:GetPlayers()

	script.Parent.Parent.SkipButton.Text = "Skips("..script.Parent.Parent.Skips.Value.."/"..TotalPlayers..")"
	if script.Parent.Parent.Skips.Value == TotalPlayers then
		print("works")
	end
end

I told him to place that variable on the while loop but he said that it doesnt work.

Anyways, he should consider that otherwise the value will remain the same after the script runs

if statement isnt running still.?

Weird, I’ve tested it out and worked?!

it seems that its the totalplayers thing since I changed it with another value and it worked but if i change it to totalplayer it doesnt work