How to use Running rbxevent?

I have a huge problem! when a rig walks towards the player, the walk animation triggers several times, I would just like it to walk towards the player by playing the animation once

--Part of code (module script)
humanoid.Running:Connect(function(speed: number)
		if speed > 0 then
			print("is running")
			walkAnimation:Play()
		else
			walkAnimation:Stop()
		end
	end)
--part of code (script)
while true do
			local magnitude = (humanoidRootPart.Position - model.HumanoidRootPart.Position).Magnitude
			
			task.wait(0.3)
			
			if magnitude <= 40 then
				model.Humanoid:MoveTo((humanoidRootPart.CFrame * CFrame.new(0, 0, 5)).Position)
			end
		end
2 Likes

Just edit roblox default script for walking, it is someswhere in starterplayerscriprs of startercharacterscripts when running the game

2 Likes

its not my objective sorryyy !^^

Maybe try checking if there is a playing animation already

noo, the output print: :arrow_forward: is running (x52)

x) is a problem

Not sure what you mean

--Part of code (module script)
humanoid.Running:Connect(function(speed: number)
		if speed > 0 then
			print("is running")
			if not walkAnimation.IsPlaying then
				walkAnimation:Play()
			end
		else
			walkAnimation:Stop()
		end
	end)
1 Like

my problem persists… x)))) ^^

Any errors? Try moving the print inside of the if not walkAnimation... statement.

I think the loop while true do is the problem

You can try putting a print where the animation is stopped to see if that’s an issue

I may have the mistake that the rig will follow the player a point A → B well the problem is that it will be all the time and cause this kind of problem but to solve it I do not know too much

Can you try implementing the changes I suggested? It could help me pinpoint the error and try to make a better fix.

--part of module
humanoid.Running:Connect(function(speed: number)
		if speed > 0 then
			if not walkAnimation.IsPlaying then
				walkAnimation:Play()
			end
		elseif speed <= 0 then
			walkAnimation:Stop()
		end
	end)
part of script
local function onPlayerAdded(player: Player)
	local model = newBoss:SetProperty()
	
	local function onCharacterAdded(char: Model)
		local humanoidRootPart = char:FindFirstChild("HumanoidRootPart"):: BasePart
		
		while true do
			task.wait(0.1)
			local magnitude = (humanoidRootPart.Position - model.HumanoidRootPart.Position).Magnitude
			
			model.Humanoid:MoveTo((humanoidRootPart.CFrame * CFrame.new(0, 0, 5)).Position)
		end
	end
	
	player.CharacterAdded:Connect(onCharacterAdded)
end

Add the prints that I suggested please

	humanoid.Running:Connect(function(speed: number)
		if speed > 0 then
			if not walkAnimation.IsPlaying then
				print("animation played")
				walkAnimation:Play()
			end
		elseif speed <= 0 then
			print("Animation finish")
			walkAnimation:Stop()
		end
	end)

What prints when the humanoid runs?

many times: animation played(x35) etc…

Does animation finish ever print? Maybe change it into a boolean if IsPlaying doesn’t work.

no, view my output

That means that the animation is constantly stopping and starting again because the running speed changes