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

Detect if a textbutton is being held?

Asked by 5 years ago

Hello, im making a cannon script where you can control it from a gui, but there is a problem, when i want to rotate i made it so you can hold it and it keeps rotating but it just does it once I tried this

local touching = false


script.Parent.MouseButton1Click:Connect(function()
    touching = true
    coroutine.resume(coroutine.create(function()
    repeat
        script.Parent.Parent.fire:FireServer("rotate","left")
        wait(0.1)
    until touching == false
    end))
end)
script.Parent.MouseButton1Up:Connect(function()
    touching = false
end)

What could i do to fix this problem?

1 answer

Log in to vote
1
Answered by 5 years ago

I think I have figured out your problem. You're using MouseButton1Click instead of MouseButton1Down. MouseButton1Click only fires when a mouse has completed a full left click (i.e. button down then button up). Changing

script.Parent.MouseButton1Click:Connect(function()

to

script.Parent.MouseButton1Down:Connect(function()

should do the trick. Hope I helped!

0
Oml i didn't notice that thanks maumaumaumaumaumua 628 — 5y
Ad

Answer this question