but everytime I use it, It will do nothing, and then when I put script.Parent.MouseClick:connect(onClick) at the bottom of the script, It will freeze my game and put very high numbers on it when I want it to be smooth
You don’t have a wait inside of the while loop, so it will increase the value 100s of times a second, causing immense lag. Try this:
function onClick()
while wait(0.1) do
game.Workspace.Temp.Value = game.Workspace.Temp.Value+2
end
end
script.Parent.MouseClick:connect(onClick)
Also, what is currently going to happen is every time they click the button, it will make a new connection. That means that if they pressed it 10 times, you would have 10 While loops going on forever. Is that what you want?
There are more efficient ways to do this using coroutines, but this is a simple way that is easier to understand.
local increasing = false
script.Parent.MouseClick:Connect(function()
increasing = not increasing --set "increasing" to the opposite of what it is (true to false) or (false to true)
end
while wait(0.5) do
if increasing == true then --check if we want to increase it
game.Workspace.Temp.Value = game.Workspace.Temp.Value+2
end
end