-
What do you want to achieve? If a person was facing a wall and walked into it they get pushed back. (The push back method I already figured out, Body Velocity)
-
What is the issue? I can’t manage to figure out a valid method.
Do you want the player to be pushed back from whatever side they touched it, or just in a specific direction?
I don’t quite understand what you want to achieve, but something like this would push them back from wherever they come;
local Debris = game:GetService("Debris")
local touchPart = workspace.Part
touchPart.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") or hit.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local character = humanoid.Parent
local humanoidRootPart = character.HumanoidRootPart
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.P = 1000
bodyVelocity.Velocity = (humanoidRootPart.CFrame * CFrame.new(0, 0, 50)).Position
bodyVelocity.Parent = humanoidRootPart
Debris:AddItem(bodyVelocity, 1)
end
end)
You can adjust the P/Velocity but this should give you an idea.
You can also use BodyPositions or BodyForces, I’m pretty sure. BodyPositions would be the easier option ig.
With BodyPositions, it works kinda better imo, so here is the code for that;
local Debris = game:GetService("Debris")
local touchPart = workspace.Part
touchPart.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") or hit.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local character = humanoid.Parent
local humanoidRootPart = character.HumanoidRootPart
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyPosition.Position = (humanoidRootPart.CFrame * CFrame.new(0, 0, 50)).Position
bodyPosition.Parent = humanoidRootPart
Debris:AddItem(bodyPosition, 0.5)
end
end)
just in a specific direction, if they touch a part facing forward the get pushed back, however if the player tried to touch the part from their backs or sideways the effect doesnt work.