Hi, im making a system where the player has to spam E, its very simple the way i wanna do it but there is something not working and its the fact that is not subtracting the value
take a look at my script:
local clickChain = game.ReplicatedStorage.Chain
if clickChain then
if clickChain.Value > 0 then
while clickChain.Value > 0 do
wait(1)
clickChain.Value = clickChain.Value - 1
end
elseif clickChain.Value >= 21 then
print("SUCCESSSS")
end
end
this bassically detects if the value is higher than 0 and subtracts 1 value every second, but its not doing so, the value is serversided aswell as this script. Does anyone know why?
The names are correct so dont worry i quatriple checked lol. Any help is appreciated
Not sure if this is part of the not subtracting problem, but the code within the condition “if clickChain.Value >= 21” will never run since that condition will never return true, as the condition is only checked when clickChain.Value <= 0.
local clickChain = game.ReplicatedStorage.Chain
while true do
if clickChain.Value > 0 then
while wait(1) do
clickChain.Value -= 1
end
end
if clickChain.Value >= 21 then
print("Succes")
end
wait(1)
end
You only need one loop, any nested loops will have unforseen consequences. Just have one loop, inside the loop first check if your value is over the threshold, elseif subtract your value by 1. After the checks wait(1).
the increasing spam E thing works perfectly fine just how i wanted it, i just want it to run code when the value goes over 21 if it does then run code, and in this example i wanna use print as to kinda like debug the thing
i just tested your code in studio and it worked fine, are you sure the script isn’t in a local script?
anyway if it still doesn’t work maybe try this?