I am making a zombie game with custom guns and animations made by me the animations play just fine but I’m having trouble scripting when the animations actually play this is my first time making and scripting animations here is my code, Thanks:
local player = game:GetService('Players').LocalPlayer local character = player:FindFirstChild('Character') if not character or not character.Parent then character = player.CharacterAdded:Wait() end local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") HoldHK33.OnClientEvent:Connect(function() local HoldHK33 = Instance.new("Animation") HoldHK33.AnimationId = "rbxassetid://12500621378" local Hold = animator:LoadAnimation(HoldHK33) Hold:AdjustSpeed(0.5) Hold:Play() task.wait(3.05) HoldHK() end) function HoldHK() local anim = Instance.new('Animation') anim.AnimationId = "rbxassetid://12500563703" holdHK = animator:loadAnimation(anim) holdHK:Play() holdHK:Play() holdHK:AdjustSpeed(.5) task.wait(1.99) ActuallyHoldingHk33.Value = true holdHK:AdjustSpeed(0) end local function plswork() ActuallyHoldingHk33.Value = false holdHK:AdjustSpeed(.5) end local function reloadHK33() holdHK:AdjustSpeed(.5) task.wait(.3) local reloadEvent = Instance.new('Animation') reloadEvent.AnimationId = 'rbxassetid://12500636956' local work = animator:LoadAnimation(reloadEvent) work:Play() work:AdjustSpeed(.5) task.wait(6.01) HoldHK() end local function HK33Running() RunningWithHK33BoolValue.Value = true holdHK:AdjustSpeed(.5) task.wait(.3) holdHK:Stop() ActuallyHoldingHk33.Value = false ActuallyHoldingHk33.Value = false local runAnim = Instance.new('Animation') runAnim.AnimationId = 'rbxassetid://12500330104' Running = animator:LoadAnimation(runAnim) Running:Play() Running:AdjustSpeed(.5) task.wait(.57) Running:AdjustSpeed(0) end function HK33QuitRunning() HoldHK() task.wait(.57) Running:AdjustSpeed(.5) Running:Stop() RunningWithHK33BoolValue.Value = false end HK33StoppedRunning.Event:Connect(HK33QuitRunning) HK33RunBindable.Event:Connect(HK33Running) unequipHK33.Event:Connect(plswork) HK33ReloadBindable.Event:Connect(reloadHK33)
Whenever I unequip the gun the hold animation and the crosshair appear as if I still have the tool equipped, Thanks.
There should be a few tutorials of this on youtube.
--Here's a quick script I found (not mine!): local tool = script.Parent local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/Asset?ID=8333681071" --Animation ID local track tool.Equipped:Connect(function() track = script.Parent.Parent.Humanoid:LoadAnimation(anim) track.Priority = Enum.AnimationPriority.Action track.Looped = true track:Play() end) tool.Unequipped:Connect(function() if track then track:Stop() end end)