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

How would I fix my ContextActionService script?

Here's the problem: When using game:GetService('ContextActionService') to make mobile controls for my game, I use a debounce called Allowed. It controls whether the buttons should be active or not. I tried to use this code to make it happen:

local CAS = game:GetService('ContextActionService')
while true do
if Allowed then
CAS:BindAction('function', predefinedfunction, true, Enum.KeyCode.Z)
end
end

The code seemed fine to me, until I tested it. Immediately after Allowed was set to true, It spammed the function it was binded to. I can't seem to figure out why.

Please help.

1 answer

✓ Accepted answer

There's no reason to add a loop (and you're never yielding), it's much better to get rid of it. If you want to bind the action when Allowed is set to true, simply do so where the code sets it.

1 comment

0

Thanks, I didn't realize that.

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