Player abilities causing physics issues

  1. What do you want to achieve? I want my character physics not to bug out after using certain abilities.

  2. What is the issue? (In video attached) First I show how my normal jumping is, and then use an ability in my game, after using the ability, i jump around again but i am specifically trying to jump backwards, my jumping is buggy and flings me arround occasionally similar to those old roblox vehicles that make you fling super far.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, but since its such a odd situation, the only things i could find were situations where it was roblox’s physics engine causing the issue, as for here, i have no idea. Previously in earlier versions this wasnt the case, even in moves i havent changed in a long time, they started causing this, it seems to occur typically in 2 player moves such as the one shown.

My ability code: (please do ask if you want to see some of the modules and etc not shown in this script block)

function Coded.InfiniteDropkick(Player:Player)
	if not Player or not Player.Character then return end

	local Char = Player.Character

	local Hum = Char:FindFirstChildOfClass("Humanoid")
	local HRP = Char.HumanoidRootPart
	local Torso = Char.Torso

	if not Hum or not HRP or not Torso then
		return
	end


	if Char:GetAttribute("Attacking") == true then
		warn("Attacking already bozo")
		return
	end

	Char:SetAttribute("Attacker", true)
	Hum.WalkSpeed = 0
	Hum.JumpPower = 0

	local isMovementEnabled = false
	local hit = false

	local Animation = ANIMS:WaitForChild("InfiniteDropkickWindup")
	local LoadAnimation:AnimationTrack = Hum:LoadAnimation(Animation)
	LoadAnimation.Priority = Enum.AnimationPriority.Action4
	LoadAnimation:Play()
	LoadAnimation.Ended:Connect(function()
		LoadAnimation:Stop()
	end)
	
	SlowService.Stun(Hum,1.1,0)
	
	local move = Instance.new("BodyVelocity")
	move.MaxForce = Vector3.new(math.huge,0,math.huge)
	move.Velocity = Vector3.new(1,1,1) * HRP.CFrame.LookVector * 200
	move.P = 1000000
	move.Parent = HRP
	
	local c1
	c1 = Char:GetAttributeChangedSignal("Stunned"):Connect(function()
		if Char:GetAttribute("Stunned") == true then
			c1:Disconnect()
			isMovementEnabled = false
			hit = true
			DBS:AddItem(move,0)
			LoadAnimation:Stop()
			Hum.WalkSpeed = 16
			Hum.JumpPower = 50
			Char:SetAttribute("Attacker",false)
		end
	end)

	local function moveForward(Speed)
		if isMovementEnabled then
			-- Calculate the velocity based on the root part's rotation
			local velocity = HRP.CFrame.LookVector * 200
			if Speed then
				velocity = HRP.CFrame.LookVector * 200 / Speed -- Adjust speed as needed
			end
			-- Apply velocity
			move.Velocity = velocity
		else
			if move then
				move.Velocity = Vector3.new(0, 0, 0) -- Stop movement
				move:Destroy()
			end
		end
	end
	
	local Hitboxnew = HitboxModule.new()
	Hitboxnew.Size = Vector3.new(8,5,15)
	Hitboxnew.CFrame = HRP
	Hitboxnew.Offset = CFrame.new(0,0,-7.5)

	Hitboxnew.onTouch = function(humanoid) --detects when the hitbox is touched
		if humanoid ~= Hum and not humanoid.Parent:GetAttribute("IFrame") and not humanoid.Parent:GetAttribute("InAttack") and not humanoid.Parent:GetAttribute("Blocking") and not Char:GetAttribute("Stunned") and humanoid.Health > 0 and not hit then
			hit = true
			
			humanoid.Parent:SetAttribute("Stunned", true)
			humanoid.Parent:SetAttribute("InAttack", true)
			Char:SetAttribute("IFrame", true)
			Char:SetAttribute("InAttack", true)
			
			c1:Disconnect()

			local OtherChar = humanoid.Parent
			local OtherTorso = OtherChar.Torso

			local EHRP = humanoid.Parent.HumanoidRootPart
			LoadAnimation:Stop()

			local AttackerAnimation = Hum:LoadAnimation(ANIMS.InfiniteDropkickAttacker)
			AttackerAnimation.Priority = Enum.AnimationPriority.Action4
			AttackerAnimation:Play(0)
			AttackerAnimation.Ended:Connect(function()
				AttackerAnimation:Stop(0)
			end)

			local MAINVFX = VFX.InfiniteDropkick

			local VictimAnimation = humanoid:LoadAnimation(ANIMS.InfiniteDropkickVictim)
			VictimAnimation.Priority = Enum.AnimationPriority.Action4
			VictimAnimation:Play(0)
			VictimAnimation.Ended:Connect(function()
				VictimAnimation:Stop(0)
			end)

			Hum.AutoRotate = false
			humanoid.AutoRotate = false

			task.spawn(function()
				for i = 1,8  do
					if HRP and EHRP then
						HRP.Anchored = true
						EHRP.Anchored = true
						Configs.BindPlayers(Player, Char, humanoid.Parent, CFrame.new(0,0,0), false)
						HRP.Anchored = true
						EHRP.Anchored = true
						task.wait(.1)
					end
				end
			end)
			
			task.wait(.3)
			
			local HitEffect = MAINVFX.Victim:Clone()
			DBS:AddItem(HitEffect,3)
			if OtherChar and OtherChar:FindFirstChild("Head") then
				HitEffect.Parent = OtherChar.Head
				for i,v in pairs(HitEffect:GetChildren()) do
					v:Emit()
				end
			end
			
			task.wait(.433)
			
			local CharEffect = MAINVFX.Attacker:Clone()
			if Char and Torso then
				CharEffect.Parent = Torso
				for i,v in pairs(CharEffect:GetChildren()) do
					if v:IsA("ParticleEmitter") then
						v:Emit()
					end
				end
			end
			
			local Player2 = game.Players:GetPlayerFromCharacter(OtherChar)

			local CSRemote = Remotes:WaitForChild("NewCutscene")
			if Player then
				CSRemote:FireClient(Player, "Coded", "InfiniteDropkick", 9.267, HRP)
			end
			if Player2 then
				CSRemote:FireClient(Player2, "Coded", "InfiniteDropkick", 9, HRP)
			end
			
			task.wait(3.3)
			
			DBS:AddItem(CharEffect,0)
			
			task.wait(5.7)
			
			if EHRP and humanoid then
				EHRP.CFrame = EHRP.CFrame * CFrame.new(0,0,3)
				
				task.wait(.02)
				
				EHRP.Anchored = false
				humanoid.AutoRotate = true

				humanoid.Parent:SetAttribute("Stunned", false)
				humanoid.Parent:SetAttribute("InAttack", false)

				local Damage = 50

				local Center = (EHRP.Position - HRP.Position).Unit

				local knockback = Center * 150

				HitService.Hit(humanoid, Damage, 3, knockback, true, 3, Player)

				local HitEffect2 = MAINVFX.Victim:Clone()
				DBS:AddItem(HitEffect2,3)
				if OtherChar and OtherChar:FindFirstChild("Head") then
					HitEffect2.Parent = OtherChar.Head
					for i,v in pairs(HitEffect2:GetChildren()) do
						v:Emit()
					end
				end
			end
			
			task.wait(.267)
			
			if HRP and Hum and Char then
				HRP.Anchored = false
				Hum.AutoRotate = true
				Char:SetAttribute("IFrame", false)
				Char:SetAttribute("InAttack", false)
				Char:SetAttribute("Attacker", false)
			end
		end
	end
	
	task.spawn(function()
		task.wait(.2)
		Hitboxnew:Start()
		task.wait(.5)
		Hitboxnew:Stop()
		Hitboxnew:Destroy()
	end)

	local Speed = 2

	task.spawn(function()
		isMovementEnabled = true
		task.wait(.8)--endofrun
		isMovementEnabled = false
		DBS:AddItem(move,0)
		task.wait(.3)
		if hit == false and Char and Hum then
			Hum.WalkSpeed = 16
			Hum.JumpPower = 50
			Char:SetAttribute("Attacker",false)
			c1:Disconnect()
		end
	end)

	repeat
		moveForward(Speed)
		print(Speed)
		wait()
	until isMovementEnabled == false
end

Quick summary of the script above:

Start: windup animation with velocity and hitbox
Hitbox function that begins the cutscene and effects
Players anchored and put in same position and rotation via “BindPlayers”
Cleanup
End

Video mentioned: (Linked due to file size limits)

If someone could take the time to help me out here I’d greatly appreciate it, this has been an issue for a couple of weeks now and people keep reporting it to me, and i dont really know what to do about it.

A quick look at your script and I noticed something that could potentially be making the issue. It looks like it in the video as well.

You have the isMovementEnabled variable and you check it in a loop. If the variable is true you create the velocity (the flinging you see) and after 0.8 seconds you remove it. (looks like its occurring every 0.8 seconds in the video too) So there is a problem there somewhere ( I leave that to you :slight_smile: )

Quick tip is also to start splitting your code up in smaller functions so it will be easier to read and debug if things like this happen.

2 Likes

Heya. Thanks for trying to help, I tried removing the velocity to try and isolate the issue, but it seems like that isnt the problem, the same issue still ocurred afterwards, thanks again!

Does it only occur when you jump or also when you just stand still?

Oh, I just managed to isolate the issue after experimenting for a while with removing key aspects of the code.,

task.spawn(function()
	for i = 1,8  do
		if HRP and EHRP then
			HRP.Anchored = true
			EHRP.Anchored = true
			Configs.BindPlayers(Player, Char, humanoid.Parent, CFrame.new(0,0,0), false)
			HRP.Anchored = true
			EHRP.Anchored = true
			task.wait(.1)
		end
	end
end)

In this script i loop 8 times through a module that makes the players move to the same spot, i do this multiple times over to make sure players stay in the correct position because i used to have issues with misaligned characters in the past.

This is the Configs.BindPlayers() function i made.

function Configs.BindPlayers(Player, Char, Enemy, EnemyOffset, Face)
	if not Player or not Char or not Enemy then return end
	local success, errorMessage = pcall(function()
		local HRP:BasePart = Char.HumanoidRootPart
		local Hum = Char:FindFirstChildOfClass("Humanoid")
		local Torso = Char.Torso
		local humanoid = Enemy.Humanoid

		if not Hum or not Player or not humanoid or not Torso then return end

		local EnemyHumanoidRootPart:BasePart = Enemy.HumanoidRootPart
		if not EnemyHumanoidRootPart then return end
		
		Hum.AutoRotate = false
		humanoid.AutoRotate = false
		HRP.Anchored = false
		EnemyHumanoidRootPart.Anchored = false

		local function updatePosition()
			local attackerPosition = HRP.Position
			local Y = HRP.Orientation.Y 

			local attackerFlatCFrame = CFrame.new(attackerPosition) * CFrame.Angles(0, math.rad(Y), 0)
			HRP:PivotTo(attackerFlatCFrame)
			if not EnemyOffset then
				if Face then
					EnemyHumanoidRootPart:PivotTo(HRP.CFrame * CFrame.Angles(HRP.CFrame.Rotation.X, math.rad(180), HRP.CFrame.Rotation.Z))
				else
					EnemyHumanoidRootPart:PivotTo(HRP.CFrame)
				end
			else
				if Face then
					EnemyHumanoidRootPart:PivotTo(HRP.CFrame * EnemyOffset * CFrame.Angles(HRP.CFrame.Rotation.X, math.rad(180), HRP.CFrame.Rotation.Z))
				else
					EnemyHumanoidRootPart:PivotTo(HRP.CFrame * EnemyOffset)
				end
			end
			
			local remoteEvent = RS:FindFirstChild("Posreset") or Instance.new("RemoteEvent")
			remoteEvent.Name = "Posreset"
			remoteEvent.Parent = RS
			
			if Player then
				remoteEvent:FireClient(Player, attackerFlatCFrame, HRP.CFrame)
			end
		end

		updatePosition()
	end)
	
	if not success then
		warn("Error in Binding Player Function: " .. errorMessage)
		Configs.ResetPlayer(Player)
	end
end

Not too sure of the issue here… any idea?

It is just when i jump in any direction other than forwards.

Hi all!

I managed to find a solution to my problem.
I found that the issue as a whole was anchoring the players seemed to be causing network ownership / physics issues with the conflicting server and clients, still not sure how this all happened because its only a recent issue despite much of my ability logic being the same for months.

Fixing the issue for me involved using welds and keeping both players in the same position, luckily for now this seems to have been the ideas solution after some testing.

Thanks again for those who tried to help. Ill mark this as the solution and let you know if anything else happens.

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