IntValue Limits

I want to make it so that if the value of an IntValue is over 1, it will cancel a function.

Here’s the script:

local clickDetector = game.Workspace.MageDoor.ClickDetector
local MageDoor = script.Parent
local HowManyClicksOnDoor = game.Workspace.MageDoor.HowManyClicksOnDoor
	
function onMouseClick()
	MageDoor.Transparency = 1
	MageDoor.CanCollide = false
	wait(5)
	MageDoor.Transparency = 0
	MageDoor.CanCollide = false
	HowManyClicksOnDoor.Value = HowManyClicksOnDoor.Value + 1 
end

clickDetector.MouseClick:connect(onMouseClick)

if HowManyClicksOnDoor.Value == 2 then --This is where I need help
	
end

Lots of Lols,
ParkCityUSA

I don’t quite understand what your asking for.

You can easily stop code from running with an if statement:

if HowManyClicksOnDoor.Value <= 1 then
    -- It'll only do whats inside here if the value is 1 or lower. 
end

If what you’re attempting to do is only allow the player to use the door twice you can throw in the if statement inside the onClick function.

function onMouseClick()
    if HowManyClicksOnDoor.Value  <= 1 then 
	    MageDoor.Transparency = 1
    	MageDoor.CanCollide = false
    	wait(5)
    	MageDoor.Transparency = 0
    	MageDoor.CanCollide = false
	    HowManyClicksOnDoor.Value = HowManyClicksOnDoor.Value + 1 
    end
end

Try


if HowManyClicksOnDoor.Value >= 2 then
  -- do stuff
end

1 Like

or

if HowManyClicksOnDoor.Value > 1 then
  -- do stuff
end
1 Like

But how would you stop the function from running?

You could return end if the value of HowManyCliskOnDoor is more than 1

1 Like

Nevermind I found a different way lol But you guys can try

Try this:

local clickDetector = game.Workspace.MageDoor.ClickDetector
local MageDoor = script.Parent
local HowManyClicksOnDoor = game.Workspace.MageDoor.HowManyClicksOnDoor
	
function onMouseClick()
	MageDoor.Transparency = 1
	MageDoor.CanCollide = false
	wait(5)
	MageDoor.Transparency = 0
	MageDoor.CanCollide = false
	HowManyClicksOnDoor.Value = HowManyClicksOnDoor.Value + 1 
end

connection = clickDetector.MouseClick:connect(onMouseClick)

if HowManyClicksOnDoor.Value == 2 then --This is where I need help
	connection:Disconnect()
end

I found it here: https://developer.roblox.com/en-us/recipes/How-to-disconnect-an-event-connection

1 Like