Animations needs to stay in place

Hey DevForum, I need your opinion on what the best way to accomplish the following, especially since I am not great with ROBLOX specific elements like animations.

I have an animation: https://youtu.be/BUSvKvdb_SY

Currently, as you might be able to see, the player goes back to the starting position after the animation. I don’t want this to happen tho.

I need the player’s arms to stay.

Opinions on how to do this?

Thanks in advance!

You could loop an animation that only has the character’s arms in that position. i.e. play an animation to get the arms to that position, then another animation to keep them there.

1 Like

You could do as @hio555 suggest, I’ve done it before. Or you could pause the animation.
To pause the animation when the arms are up, you will need a Marker in the animation.

Once tracker is named and published to animation. Just add the code below.

-- animtrack = animation
animtrack:GetMarkerReachedSignal("Stop"):Wait() -- change *Stop* to marker name
animtrack:AdjustSpeed(0) -- pauses
task.wait(3) 
animtrack:AdjustSpeed(1) -- resumes
1 Like

And where should I add this to my script?

My script:

local Players = game:GetService('Players')
local LocateAnimation = script.Parent:WaitForChild('Animation')
local Character = Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild('Humanoid')
local Animation = Humanoid:LoadAnimation(LocateAnimation)

script.Parent.Equipped:connect(function()
	Animation:Play()
end)
script.Parent.Unequipped:Connect(function()
	Animation:Stop()
end)
local Players = game:GetService('Players')
local LocateAnimation = script.Parent:WaitForChild('Animation')
local Character = Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild('Humanoid')
local Animation = Humanoid:LoadAnimation(LocateAnimation)

script.Parent.Equipped:connect(function()
	Animation:Play()
---> overhere
---> find the animations "Marker" Using "Animation.GetMarkerReachedSignal"

      Animation.GetMarkerReachedSignal:Once(function()
---> And Use @Trainmaster2341's Code
      end)

end)
script.Parent.Unequipped:Connect(function()
	Animation:Stop()
end)

also, i maybe wrong about the GetMarkerReachedSignal’s thing. i dont use it much so idk how to handle it properly, i hopes you can still use it tho :slight_smile:

Sorry, I am not a scripter, but would a swap his

> animtrack:GetMarkerReachedSignal("Stop"):Wait() -- change *Stop* to marker name
> animtrack:AdjustSpeed(0) -- pauses
> task.wait(3) 
> animtrack:AdjustSpeed(1)

with:

animation:GetMarkerReachedSignal("Stop"):Wait() -- change *Stop* to marker name
animation:AdjustSpeed(0) -- pauses
task.wait(3) 
animation:AdjustSpeed(1)

If you can’t tell I swapped animtracks with animations.

Everything is explained in the script(Server).

:warning:Remember! Your animation needs a Marker in it, or else it wont work.

local tool = script.Parent -- scipt directly under tool

local toolEquipped = false -- bool value
local LocateAnimation = script.Parent:WaitForChild("Animation") -- your animation
local animation:AnimationTrack = nil -- set as playng animtion(don't mess)
local db = 1 -- debounce(run code once)

local function useTool()
	if db == 1 and toolEquipped then -- if debounce is done and player is holding tool
		db = 2 -- change debounce(so function wont run again till it's 1 again)
		local humanoid:Humanoid = script.Parent.Parent:FindFirstChild("Humanoid") -- too will be in character when equipped
		if not humanoid then
			print(script.Parent.Parent.Name .. "has no Humanoid") -- error
		else
			animation = humanoid.Animator:LoadAnimation(LocateAnimation) -- load the animation
		end
		if animation then -- checks if the animation exist
			print("played animation")
			animation:Play() -- play the animation
			animation:GetMarkerReachedSignal("Stop"):Wait() -- change *Stop* to marker name
			animation:AdjustSpeed(0) -- pauses
			print("paused")
			task.wait(3) 
			if not animation or not toolEquipped then return print("animation was cancled") end -- checks if tool was still equipped
			-- give health? or something
			animation:AdjustSpeed(1) -- resumes
			print("resumed")
			animation.Ended:Wait() -- wait till animation finished(can trigger if stopped)
			animation = nil -- reset animation
			print("Finished!😁")
		end
		db = 1 -- change debounce(if animation don't play/exist it will still change)
	end
end

local function lostTool()
	if not toolEquipped and db == 2 then -- checks if useTool function is running
		if animation and animation.IsPlaying then -- animation exist and is playing
			animation:Stop()
			animation = nil -- reset animation
		end
	end
end

tool.Equipped:Connect(function()
	toolEquipped = true
	useTool()
end)

tool.Unequipped:Connect(function()
	toolEquipped = false
	lostTool()
end)

Take note! Avoid putting functions in the

tool.Equipped

and

tool.Unequipped

Functions, from experience they seem to fire multiple times and can cause issues. So just use them for little events/checks or as in the script above(boolValues) though I did fire functions through them. That’s why there is a debounce, to make sure they only run once. As for the unequipped function, it has little to no harm running multiple times.

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