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

Detect if a textbutton is being held?

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

✓ Accepted answer

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!

1 comment

0

Oml i didn't notice that thanks

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