Hey scriptinghelpers, two questions same script. So, the script below is a LocalScript in StarterGui, on key pressed (the key is Q/mobile button) run animation. I'm actually having two problems with this script. The first one is my debounce isn't working so, if you press Q repeatedly it just keeps running the animation over and over for each time you press it (meaning it starts over basically). The second problem I'm having is that it adds the value to leaderstats then it immediately subtracts that value it just added, which I don't understand. I appreciate the help. Thanks in advance!
This is a LocalScript in StarterGui
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local cas = game:GetService("ContextActionService")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://27789359"
local debounce = false
function OnKeyPressed(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin and debounce == false then
debounce = true
humanoid:LoadAnimation(animation):Play()
wait(10)
local animationTracks = humanoid:GetPlayingAnimationTracks()
for _, t in pairs (animationTracks) do
t:Stop()
player.leaderstats.Tix.Value = player.leaderstats.Tix.Value + 100
debounce = false
end
end
end
cas:BindAction("PlayAnim", OnKeyPressed, true, Enum.KeyCode.Q)
cas:SetPosition("PlayAnim", UDim2.new(1, -70, 0, 10))

2 comments
Oh sweet, thanks for the help! I appreciate it. I'm not really trying to do much with it, I just was having a hard time because, last time I used RemoteEvent it wasn't working properly so I didn't really understand. I'm only here to learn! The script is just so I can learn about on key pressed and I wanted to add some type of value. Thanks again though.
You did a really good job explaining so, I appreciate that. I understand a lot better now.