Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make something happen while left click is held down?

Hello, I'm fairly new to scripting. I was testing out things and couldn't figure out how to make something happen while left click is held down. I am trying to make x-ray goggles. I want it to be green and halfway transparent while the left click is held down and normal when not. This is what I have so far. As you can see, right now if you click once and changes for 20 secs and reverts back to normal.

   local Door = game.Workspace.Doory
	local Tool = script.Parent 
 
Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function() 
		 Door.Transparency = 0.5
		 Door.BrickColor = BrickColor.new("Camo")
		wait(20)
		 Door.Transparency = 0
		 Door.BrickColor = BrickColor.new("Dark stone grey")
	end)
end)

Any help would be appreciated.

1 answer

I'm not sure if it will work, but try to create a mouse variable:

local Door = game.Workspace.Doory
	    local Tool = script.Parent
	local mouse =  game.Players.LocalPlayer:GetMouse
	Tool.Equipped:Connect(function(Mouse)
	    mouse.Button1Down:Connect(function()
	         Door.Transparency = 0.5
	         Door.BrickColor = BrickColor.new("Camo")
	        wait(20)
	         Door.Transparency = 0
	         Door.BrickColor = BrickColor.new("Dark stone grey")
	    end)
	end)

try to put that script in a script location if possible and try again

4 comments

0

Did what the old script did but I wan't it to go transparent while the button is held down and switch back when it is not.

0

what do you specifycally want?

0

Sorry i'm late but I just saw this. I'm trying to have the brick color and transparency change ONLY when the button is being held down. Then when I let go of the right click the part gets back it's original properties.

0

did you manage to do that?

This discussion is preserved as it was. New answers, comments, and votes are closed.