I need help with a script

U means something like this instead of 20 loops?

local clickChain = game.ReplicatedStorage.Chain

while true do
	if clickChain.Value > 21 then
			print("Succes")
		
		elseif clickChain.Value > 0 and clickChain.Value < 21 then
		while wait(1) do
			clickChain.Value -= 1
		end
	end
	wait(1)
end

image

How would that look like in a script tho i never used β€œfor” loops

Dont check yhe variable, it wont update its value as the object changes

The clickChain variable? Thats the intvalue, so i have to check it right? (Sorry if im being dumb)

local clickChain = game.ReplicatedStorage.Chain

if clickChain then
	if clickChain.Value > 0 then
		for i = 1, clickChain.Value do
wait(1)
clickChain.Value -= 1
end
	elseif clickChain.Value >= 21 then
		print("SUCCESSSS")
	end
end

yeah so that didnt work, putting it in a while loop did something but gave me a error i have never seen before:

17:31:55.810 ServerScriptService.ChainSystem.ErafHalenG:8: attempt to perform arithmetic (sub) on Instance and number - Server - ErafHalenG:8

oops forgot to put clickChain.Value
do that in the for loop

1 Like

Nevermind, youre right xD [char limit]

nah i made it:

local clickChain = game.ReplicatedStorage.Chain

while true do
    if clickChain then
        if clickChain.Value > 0 then
            for i = 1, clickChain.Value do
                wait(1)
                clickChain.Value = clickChain.Value - 1
            end
        elseif clickChain.Value >= 21 then
            print("SUCCESSSS")
        end
    end
    wait(1)
end

and it worked, but why isnt it printing succes, its the most logical thing it checks if the things value is 21 and prints, how hard is it i have no other solutions

you kinda made it check if its above 0 first, and 21 is above 0…
simple fix, put the if >= 21 first and the check later

local clickChain = game.ReplicatedStorage.Chain

while true do
    if clickChain then
        if clickChain.Value >= 21 then
            print("SUCCESSSS")
        elseif clickChain.Value > 0 then
            for i = 1, clickChain.Value do
                wait(1)
                clickChain.Value = clickChain.Value - 1
            end
        end
    end

    wait(1)
end

made it that and it worked, amazing thank you, and the other guy for taking time out of ur day to help

3 Likes

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