How to run a line of code only when a certain condition is met

You can write your topic however you want, but you need to answer these questions:

  1. I am trying to make a JoJo game, and with that I need to be able to run a attack only when the Stand is equipped. I’ve been trying to do So for About a hour.

So Far I’ve tried running loops, only firing when the mouse button is clicked, the basics.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local mouse = game.Players.LocalPlayer:GetMouse()

local debouce = false
local isActive = false
local cd = 4

mouse.Button1Down:Connect(function()
	if debouce == false and isActive == false then
		debouce = true
		isActive = true
		
		if isActive == true then
			print("Stand Is Equipped and Ready to attack")
		else
			print("Please Equipt Stand To Attack")
		end
	end
end)

The RE is going to be used in the future, I need to get this local script working first.

Hi, you can use an if statement. For example:

local beans = "hello"
if beans == "hello" then
     print("BEAN MAN RETURNS")
end

I’ve used multiple if statements? Did you even read the block of code provided?

I’m confused, if statements are what run a line of code when a condition is met. Do you mean you want to wait until the condition is met?

You are missing an if statement for checking if the player is equipping the tool.

local tool = -- Define tool here
local mouse = game.Players.LocalPlayer:GetMouse()

local debouce = false
local cd = 4

mouse.Button1Down:Connect(function()
	if debouce == false then
		debouce = true
		
		if tool.Equipped == true then
			print("Stand Is Equipped and Ready to attack")
		else
			print("Please Equipt Stand To Attack")
		end
        wait(cd)
	end
end)

The stand is not a tool in this situation, do you think making a bool value and when it is equipped it runs a check?

I mean when the stand is equipped, therefore it does not interfere with other gameplay elements. I didn’t exactly know what to put for a good title :sweat_smile:

Yes, using a bool value will work with this script:

local value = -- Define BoolValue here
local mouse = game.Players.LocalPlayer:GetMouse()

local debouce = false
local cd = 4

mouse.Button1Down:Connect(function()
	if debouce == false then
		debouce = true
		
		if value.Value == true then
			print("Stand Is Equipped and Ready to attack")
		else
			print("Please Equipt Stand To Attack")
		end
        wait(cd)
	end
end)
1 Like

Okay thank you, I appreciate it! Have a nice day :slight_smile:

Oh! Ok, I think I know how do this.

local mouse = game.Players.LocalPlayer:GetMouse()
local holding = false
mouse.Button1Down:connect(function()
     if holding == true then
          -- run code here
     end
end)

script.Parent.Equipped:connect(function()
     holding = true
end)

script.Parent.Equipped:connect(function()
     holding = false
end)

By the way, this has to be in a localscript inside the tool.