Hello! I want to make it such that when a player clicked on the screen or the mouse when the tool is equipped, the character will play an animation. Currently, in this script, the animation played out perfectly. However, I don’t want the animation to play from the beginning again when the player clicked on the screen and the previous animation haven’t finished playing. I tried using debounce as shown in this code below but it still doesn’t work. Is there anyway I can solve this issue?
local rice = script.Parent
local animation = rice.Animation
local hasstart = true
rice.Activated:Connect(function()
local character = rice.Parent
if character:WaitForChild("Humanoid") and hasstart == true then
print("true")
hasstart = false
print("false")
local lefthand = character:WaitForChild("LeftHand")
local spoon = game.ReplicatedStorage.Spoon:Clone()
spoon.Parent = character
local newcframe = CFrame.new(0.482,-0.322,0.081)
local cframeangle = CFrame.Angles(math.rad(-2.541), math.rad(-94.529), math.rad(88.645))
local positioncframe = lefthand.CFrame * newcframe
spoon.CFrame = positioncframe * cframeangle
local weld = Instance.new("Weld")
weld.Part0 = lefthand
weld.Part1 = spoon
weld.C0 = lefthand.CFrame:Inverse()
weld.C1 = spoon.CFrame:Inverse()
weld.Parent = lefthand
local humanoid = rice.Parent:WaitForChild("Humanoid")
local track = humanoid:LoadAnimation(animation)
track:Play()
track.Stopped:Connect(function()
spoon:Destroy()
hasstart = true
print("true")
end)
end
end)