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