Knowing me there is an error in here, but i just dont know where its not working, this code is meant to make a part go invisible after 10 clicks and it does it on the first click, help will be much appreciated :) thanks!
function onClick() script.Parent.Value.Value = script.Parent.Value.Value + 1 if script.Parent.Value.Value ~= 10 then script.Parent.Transparency = 1 else end end script.Parent.ClickDetector.MouseClick:connect(onClick)
It is doing what you told it to do check the operator
You are using ~=
so lets say we had the starting value of then we add 1. 1 ~= 10
which is true
so the code will run and make the part go invisible.
We could use:-
-- this will run when the value is greater than 9 if script.Parent.Value.Value > 9 then -- this will run when the value is greater than or equal to 10 if script.Parent.Value.Value >= 10 then --- a lot of others can be used as well
Other issues:-
We do not need to access script.Parent.Value
multiple times so we should make a variable, this also helps simplify the code.
local par = script.Parent -- we create a variable to access the parent, we then use this local valObj = par.Value -- this is the object you should re-name it as value is confusing, also look into using "WaitForChild()" print('variabels added') function onClick() print('ran') valObj .Value = valObj .Value + 1 if valObj .Value == 10 then -- only run at 10 print('num is 10') par.Transparency = 1 else print('num is not 10') end end par .ClickDetector.MouseClick:connect(onClick)
I hope this helps, please comment if you do not understand how /why this code works.