Why does this line of code run ONCE only?

The line player.Character.HumanoidRootPart.Rotation = Vector3.new(0, 180 , 0) runs once only, while the other lines work normally, whats the issue?

game.ReplicatedStorage.ControlActions.RunBackAnimFor_S_Key.OnServerEvent:Connect(function(player)
	local humanoid = player.Character.Humanoid
	local anim = humanoid:LoadAnimation(game.Lighting.RUNBACK_ANIM) 
	
	humanoid.WalkSpeed = 0 
	humanoid.JumpPower = 0
	
	anim:Play()
	
	wait(anim.Length)
	
    humanoid.WalkSpeed = 16
	
	player.Character.HumanoidRootPart.Rotation = Vector3.new(0, 180 , 0) -- This line runs once
end)


game.ReplicatedStorage.ControlActions.RunBackAnimFor_A_Key.OnServerEvent:Connect(function(player)
	local anim = player.Character.Humanoid:LoadAnimation(game.Lighting.test)
	anim:Play()
end)
1 Like

i dont know for sure if its that but u can try adding the value instead of setting the value, again it may or may not work. So like

player.Character.HumanoidRootPart.Rotation += Vector3.new(0, 180 , 0)

or else just use cframes, i hope this will work for u

1 Like

It seems like the Line runs only once because it sets the Rotation of the HumanoidRootPart of the character to a fixed value (0, 180, 0) every time the event is triggered. After it’s set once, it subsequent attempts to set it to the same value won’t have any noticeable effect visually.
Might be wrong, but I think thats the case here

1 Like

This dude explained what i did in the reply above :+1: Both our replies should work

1 Like

thank you @Sentlyee and @emiliotigre2017 for the help!, however i managed to fix the problem myself with an if statement, which is a kinda dum solution but it works:

local r = true -- Changed

game.ReplicatedStorage.ControlActions.RunBackAnimFor_S_Key.OnServerEvent:Connect(function(player)
	local humanoid = player.Character.Humanoid
	local anim = humanoid:LoadAnimation(game.Lighting.RUNBACK_ANIM) 
	
	humanoid.WalkSpeed = 0 
	humanoid.JumpPower = 0
	
	anim:Play()
	
	wait(anim.Length)
	
    humanoid.WalkSpeed = 16
	
	if r then -- Changed
	player.Character.HumanoidRootPart.Rotation = Vector3.new(0, 180 , 0)
	end
end)

game.ReplicatedStorage.ControlActions.RunBackAnimFor_A_Key.OnServerEvent:Connect(function(player)
	local anim = player.Character.Humanoid:LoadAnimation(game.Lighting.test)
	anim:Play()
end)

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