Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
lytew 99
4 years ago
Edited 4 years ago

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

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. wildmanx20 35 — 4y
0
what do you specifycally want? lytew 99 — 4y
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. wildmanx20 35 — 4y
0
did you manage to do that? lytew 99 — 4y
Ad

Answer this question