Checking a character's position

Hello! There is a mechanic in my game where after holding E next to a player for a while, you can finish them off. However, I want to make it such that the player holding E is disadvantaged in movement to make sure players cannot move around while holding E, making it harder to target them. I made a system where a server script would check if the player’s character’s humanoidrootpart has changed position every heartbeat (Run service), and if the humanoidrootpart has changed position, the player will be forced to stop executing the other player. However, when I tried implementing this, it caused a few problems, such as the the player being forced to stop when they only rotate their character via shiftlock, or the player being forced to stop when they just stopped walking because they still carry momentum from the movement.

How would I go about fixing this problem? Or, if you can think of a better way to balance the movement of the character while they are finishing another player off, please tell me.

local PreviousPosition = Character.HumanoidRootPart.Position
		local PositionCheck = RunService.Heartbeat:Connect(function()
			if (PreviousPosition - Character.HumanoidRootPart.Position).Magnitude > 0 then
				task.cancel(StolenSoul) -- Stolen Soul is another function that handles the execution if it happens
				Events.Visual:FireClient(Player, "StealSoul", false)
				for _, Track in Character.Humanoid.Animator:GetPlayingAnimationTracks() do
					if Track.Name == "Hold" then
						Track:Stop()
					end
				end

				if Character:FindFirstChild("SoulBeamVfx") then Character.SoulBeamVfx:Destroy() end

				PlayersCurrentlyStealing[Player] = nil
			end
			PreviousPosition = Character.HumanoidRootPart.CFrame.Position
		end)

Thanks for reading the post :slight_smile:

did you try

humanoid:GetPropertyChangedSignal("MoveDirection"):Once(function()

end)

I suggest only tracking if movement has changed after the animation reaches a certain point with GetMarkerReachedSignal()

1 Like

I realised that exploiters can change their positions and it will not be seen as a change in the humanoid’s MoveDirection (I could be wrong, please let me know if I am). How would I prevent that? It was another reason why I used heartbeat.

They can on their client, but I don’t think if they changed it on Client, it would replicate to server.

You’re only going to make code less efficient and more complicated trying to control something you have no control over

The only solution over position and velocity are server authoritative characters

You can read articles about it. There is also a resource available here in the devforum called
Chickynoid.

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