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))
Your debounce isn't working because it's inside a for loop. Also, you cannot change leaderstats values through a local script, you'll have to use a remote event.
Here is a quick way
Local script :
local player = game.Players.LocalPlayer local character = player.Character --Add a remote event in the replicatedstorage local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") 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) debounce = false --I don't know if this is when you want to give the stats RemoteEvent:FireServer("Tix") local animationTracks = humanoid:GetPlayingAnimationTracks() for _, t in pairs (animationTracks) do t:Stop() end end end cas:BindAction("PlayAnim", OnKeyPressed, true, Enum.KeyCode.Q) cas:SetPosition("PlayAnim", UDim2.new(1, -70, 0, 10))
Server script :
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") RemoteEvent.OnServerEvent:Connect(function(plr, stat) --I recommend you add extra security check there if stat == "Tix" then plr.leaderstats.Tix.Value = plr.leaderstats.Tix.Value + 100 end end)
But yeah I don't understand what you're trying to do with this
local debounce GetChildren ("debounce") if debounce.Working = false then changeValue.debounce.Working = true if value being subtracted instead of being added then Stop