Animation script problem - help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the animation script to be fixed and hope the animation to play once whenever is long animation

  2. What is the issue? Include screenshots / videos if possible!
    Whenever i press H the animation continue playing without stoping its supposed to be play once

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Try changing the priority of animation and different plugin but still same


local lPlayer = game:GetService("Players").LocalPlayer
local char = lPlayer.Character or lPlayer.CharacterAdded:Wait()

local animations = require(game.ReplicatedStorage:WaitForChild("DrillWeapons"):WaitForChild("Settings"))

local tool = script.Parent

local animTrackTable = {}

local playingAnim = nil
local canSwitchAnim = true

for i, animData in ipairs(animations) do
	
	if table.find(animData.ToolNames, tool.Name) then
		local anim = Instance.new("Animation")
		anim.AnimationId = "rbxassetid://"..animData.AnimationID
		
		local track = char:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(anim)

		animTrackTable[animData.Keybind.Name] = {track,i}
	end

end

local ui = nil

tool.Equipped:Connect(function()
	
	if tool.MainPart.Motor6D.Part0 == nil then
		tool.MainPart.Motor6D:GetPropertyChangedSignal("Part0"):Wait()
	end
	
	
	
	if ui == nil then
		ui = game.ReplicatedStorage.DrillWeapons.KeybindList:Clone()
		ui.Parent = lPlayer.PlayerGui
		
		for _, animData in pairs(animations) do
			if table.find(animData.ToolNames, tool.Name) then
				local sample = ui.MainFrame.ScrollingFrame.Sample:Clone()
				sample.Name = animData.Name
				sample.Parent = ui.MainFrame.ScrollingFrame
				sample.TextLabel.Text = animData.Name..": "..animData.Keybind.Name
				sample.Visible = true
			end
		end
		
	else
		ui.Enabled = true
	end
	
	for _, anim in pairs(animTrackTable) do
		if anim[2] == 1 then
			anim[1]:Play()
			playingAnim = anim[1]
			break
		end
	end
	
end)

tool.Unequipped:Connect(function()
	playingAnim:Stop()
	playingAnim = nil
	canSwitchAnim = true
	ui.Enabled = false
end)

local track = nil

uis.InputBegan:Connect(function(input, typing)
	
	if typing == true then return end
	
	if tool.Parent == char and canSwitchAnim == true then
		
		if animTrackTable[input.KeyCode.Name] ~= nil then
			
			track = animTrackTable[input.KeyCode.Name][1]
			
			playingAnim:Stop()
			playingAnim = nil
			
			track:Play()
			playingAnim = track
			
			if track.Looped == false then
				
				local currentTrack = track
				
				canSwitchAnim = false
				
				while tool.Parent == char and track.TimePosition < track.Length*.99 do -- only reliable way with roblox animations :/ (getpropertychangedsignal doesn't work)
					task.wait()
				end
				
				if tool.Parent == char then
					track:AdjustSpeed(0)
				end
				
				canSwitchAnim = true
			end
			
		end
		
	end
	
end)

the problem here is that you looped the animation unknowingly and then published it.

1 Like

Sorry how to fix that problem and where i can unlooped the animation?

(took this image off of google)


load your animation and if this is blue then you have it looped so click it again, then publish

also does the animation stop upon unequipping the tool?

Look like i just had to set looped = true in the script and work now properly but ty for ur time

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.