Anti-fling script false positive

Hi, I am using an Anti-Fling script to prevent players from being flung while they are using certain tools in game, but when a player jumps the script thinks that they are being flung, and forces them onto the ground:

Script:

local Character = script.Parent.Parent
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local CurrentHum = Character:WaitForChild("Humanoid")
local CurrentRoot = Character:WaitForChild("HumanoidRootPart")

local function FlingPreventionUpdate()
	if CurrentHum ~= nil and CurrentRoot ~= nil --[[and Force ~= nil]] then
		if CurrentRoot:IsDescendantOf(Workspace) then
			if CurrentRoot.RotVelocity.Magnitude >= 50 or CurrentRoot.Velocity.Magnitude >= 50 then
				CurrentRoot.RotVelocity = Vector3.new()
				CurrentRoot.Velocity = Vector3.new()
			end
		end
	end
end

RunService.RenderStepped:Connect(FlingPreventionUpdate)

Any help would be appreciated, thanks!

1 Like

It’s because of the fact that you’re accounting for all of the coordinates, including Y. So therefore, Magnitude reaches a high value.

This should probably work.

local Character = script.Parent.Parent
local RunService = game:GetService("RunService")

local Humanoid = Character:WaitForChild("Humanoid"):: Humanoid
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart"):: Part

-- Assuming that your characters are parented to workspace.
-- If they're explicitly parented somewhere else, edit this condition.
if Character.Parent ~= workspace then
	Character.AncestryChanged:Wait()
end

local function FlingPreventionUpdate()
	-- The if statements were removed as I don't really
	-- see a reason for them to be there since the
	-- instances will always be there

	-- Do note that this doesn't account for any sort of body movers! You'd have to
	-- find a way to implement that if you have any.
	local WalkSpeed = Humanoid.WalkSpeed
	local Limit = WalkSpeed + 10
	local Velocity = HumanoidRootPart.AssemblyLinearVelocity
	local X, Z = Velocity.X, Velocity.Z
	if math.abs(X) > Limit or math.abs(Z) > Limit then
		HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
		HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero
	end
end

RunService.RenderStepped:Connect(FlingPreventionUpdate)

Thank you, but is there any way for it for to not stop you mid-air? Because I have goalkeeper animations in game, and when I use this script it stops the player mid-air while using these tools even though they haven’t hit any part

I have added to your script but it is a bit dodgy sometimes:

local Character = script.Parent.Parent



local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local Humanoid = Character:WaitForChild("Humanoid"):: Humanoid
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart"):: Part


if Character.Parent ~= Workspace then
	Character.AncestryChanged:Wait()
end

local function FlingPreventionUpdate()
	local WalkSpeed = Humanoid.WalkSpeed
	local Limit = WalkSpeed + 10
	local Velocity = HumanoidRootPart.AssemblyLinearVelocity
	local X, Z = Velocity.X, Velocity.Z
	if math.abs(X) > Limit or math.abs(Z) > Limit then
		HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
		HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero
	end
end


for _, v in pairs(game:GetDescendants()) do
	if v:IsA("Part") then
		v.Touched:Connect(function()
			FlingPreventionUpdate()
		end)
	end
end

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