Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a script that plays an animation at a specific speed?

I've tried everything I can and it doesn't work I changed the normal Roblox animation code so that if the WalkSpped is equal or more than WalkSpeed a different animation is played

local Players = game:GetService("Players") 
local runAnimation = "rbxassetid://8477846036" --Gets Animation

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid") -- Gets humanoid

	local animateScript = character:WaitForChild("Animate") --
	local walkspeed = humanoid.WalkSpeed
	if walkspeed >= 25 then
		animateScript.run.RunAnim.AnimationId = runAnimation
	elseif walkspeed < 25 then
		--
	end
end

local function onPlayerAdded(player)
	player.CharacterAppearanceLoaded:Connect(onCharacterAdded) -- Connects onCharacterAdded when the CharacterApperanceLoaded is true
end

Players.PlayerAdded:Connect(onPlayerAdded) -- Connects onPlayerAdded to PlayersAdded idk

2 answers

I tried something else in the animation script but it won't work nor save

function onRunning(Speed)
	local runAnimation = "rbxassetid://8477846036"
	if Speed >= 25  then
		animTable[3][1][1] = runAnimation
	elseif Speed < 25 then
		
	else
		--function
	end
end

You need to check if the walkspeed changes, there's a built-in function named "GetPropertyChangedSignal" to get the event of it, example script (Edited to fix the issues):


local function OnCharacterAdded(chr)
	chr.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
		local newSpeed = chr.humanoid.WalkSpeed
		if newSpeed >=  25 then
			chr.Animate.run.RunAnim.AnimationId = runId
		else
			-- Default walk animation
		end
	end) -- Get walkspeed change event, you can use this on other properties too
end

local function OnPlayerAdded(plr)
	plr.CharacterAdded:Connect(OnCharacterAdded)
	-- other stuff
end

game.Players.PlayerAddded:Connect(OnPlayerAdded)

4 comments

0

When i use this script there is alot of variable errors and i dont know how to make the changes to make the variable

0

@NoahSegasonic like what?

0

plr and humanoid

0

I'm sorry I didn't notice, editing my answer now.

This discussion is preserved as it was. New answers, comments, and votes are closed.