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

How would I fix my ContextActionService script?

Asked by 6 years ago

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

Log in to vote
2
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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.

0
Thanks, I didn't realize that. 222ono222 47 — 6y
Ad

Answer this question