I am trying to find the best way to play an animation on a humanoid when the player clicks, but make it so that animation plays the full length. I don’t want the animation to keep re-playing everytime a player clicks. If anyone has any ideas feel free to post it!
My code on the client:
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 then
if gameProcessedEvent == true then
else
game.ReplicatedStorage.Clicking:FireServer(plr)
end
end
end)
My code on the server:
game.ReplicatedStorage.Clicking.OnServerEvent:Connect(function(plr)
local playerModel = game.Workspace:FindFirstChild(plr.Name)
local humanoid = playerModel.Humanoid
plr.leaderstats.Bucks.Value = plr.leaderstats.Bucks.Value + 1
local FinalAnim = humanoid:LoadAnimation(game.Workspace.TossingMoney)
FinalAnim:Play()
end)
You should only load the animation once for each character. When you have it loaded and have a reference to it, you can check if AnimationTrack.IsPlaying of that animationtrack is true. If it’s not, play it. You could store the animationtracks of each character into a table and when the character dies, remove them from the table and load new ones when the player respawns.
You can create a value called enabled and play the animation only if the value is true and make it false when the animation starts and set it back to true when animation finishes.
Oh I see you use that for every player. In that case, make your denounce a table with player IDs as keys then have Booleans as values. Then use those values as denounces. Ex.
debounceTable = {}
Scriptsignal:Connect(function(player)
local playerId = player.UserId
if debounceTable[userId] then return end
debounceTable[userId] = true
[[code]]
otherScriptSignal:Wait()
debounceTable[userId] = nil [[ or false. ]]
end)
Again, written on my phone. I can’t write comments or indent stuff. Good luck with what your making!