How do I fling a player away from a part?

I want to make all players in the server flinged away from a certain part like this


But I am unsure how… I already have a serverscript which just makes the player go one direction

local Players = game.Players:GetPlayers()

for _, Player in pairs(Players) do
	local Character = Player.Character
	if not Character then
		continue
	end
	local Root = Character:FindFirstChild("HumanoidRootPart")
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if not Root or not Humanoid then
		continue
	end
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.Velocity = Vector3.new(1500, 1000, 0)
	BodyVelocity.MaxForce = Vector3.new(7500,7500,7500)
	BodyVelocity.Parent = Root
	Humanoid.PlatformStand = true
end

And it would be nice if it was based on the distance of the player from the part.

Create a CFrame originating at the fling part, face it towards the player’s HumanoidRootPart, and grab the LookVector of that CFrame

local fling_direction = CFrame.new(fling_part.Position, Root.Position).LookVector

Ok but how do I fling the player now?

Use Root:ApplyImpulse(fling_direction) for a momentary movement (akin to a shove), or use the BodyVelocity in your original script: BodyVelocity.Velocity = fling_direction

2 Likes

Could you make it so it only moves the player on the X and Z axis? I don’t want to player to go into the ground

Multiply the Y-axis by 0 in order to cancel it out

fling_direction * Vector3.new(1, 0, 1)
1 Like

Uhm so it’s supposed to fling the player like across the entire room, but it is only slowly sliding him on the floor. Would you know how to fix that please?

If you’re using ApplyImpulse() then change the values that you multiply by.

fling_direction * Vector3.new(1000, 0, 1000)

If using Body Movers, change the MaxForce value to something greater.

1 Like

apply impulse isn’t working for me :confused:

and it didn’t do anything it is still the same
robloxapp-20221108-1658299.wmv (809.7 KB)
with body velocity

My mistake, multiply the fling_direction by Vector3.new(1000, 0, 1000) and then put it in BodyVelocity.Velocity

Ok thanks lol but one more question, how would I make it so it flings a player more that is closer to that fling part?
(Like an explosion)

Use a negative linear function, just like an explosion damage in the documentation.