Make Player Swim (IDLE/ACTION ANIMATION)

local SwimAnimation = Instance.new('Animation')
SwimAnimation.AnimationId = 'rbxassetid://5908030188'
RAnimation = Hum:LoadAnimation(SwimAnimation)

local IdleAnimation = Instance.new('Animation')
IdleAnimation.AnimationId = 'rbxassetid://5908001922'
LAnimation = Hum:LoadAnimation(IdleAnimation)

swimmingRightNow = false

while true do
	wait()
	if cam.CFrame.Y < -10 then
		script.Parent.Frame.Visible = true
		
	elseif cam.CFrame.Y > - 10 then
		script.Parent.Frame.Visible = false
		
	end
	

	
	if char:WaitForChild("HumanoidRootPart").Position.Y <= -5 and swimmingRightNow == false then
		swimmingRightNow = true
		Swim:FireServer("Swim")
		
		print("SwimmingRIghtNow is true")
	elseif char:WaitForChild("HumanoidRootPart").Position.Y > -5 and swimmingRightNow then
		swimmingRightNow = false
		Swim:FireServer("NoSwim")
		RAnimation:Stop()
		LAnimation:Stop()
		print("SwimmingRightnow is false")
	end
end

I was wondering how to make the player play a swimming animation when the player is moving. When the player stops moving it plays an idle animation instead.

1 Like

This can be done by changing the values on the animation script located in the character.

Can I see an example on how to change the value?

Ok first you want to playtest and copy the animation script.

After stop and paste into StarterCharacterScripts.

image

And then edit the animation id property of the animation instances named swimming and swimming idle to your desired animations.

And you are done!

1 Like