How do I push the player when you touch the part

I’m making a system that pushes the player when you touch the part, but I don’t know how.

Script:

local d = false

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		if d == false then
			d = true
			wait(0.7)
			d = false
		end
	end
end)

Any help is appreciated, thanks.

2 Likes

Put this script into the part’s parent object. This can be a part, model, or any other object that contains the part you want to use for pushing the player.

local pushForce = 500 -- Adjust this value to change the strength of the push

local function onTouched(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local character = humanoid.Parent
        local bodyVelocity = Instance.new("BodyVelocity")
        bodyVelocity.Velocity = (part.Position - character.HumanoidRootPart.Position).unit * pushForce
        bodyVelocity.P = math.huge
        bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bodyVelocity.Parent = character.HumanoidRootPart

        -- Remove the body velocity after a certain amount of time
        wait(0.1) -- Adjust the duration as needed
        bodyVelocity:Destroy()
    end
end

script.Parent.Touched:Connect(onTouched)
1 Like

@ Elarahs Crazy close to how I was doing this in one of my programs.
This is just a medium push back bounce you away touch. I’m sure both work for this.

local db = false
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local Char = hit.Parent:FindFirstChild("Humanoid").Parent
		if db == false then db = true
			local bv = Instance.new("BodyVelocity")
			local offset = Vector3.new()
			bv.Parent = (Char.LowerTorso)
			bv.MaxForce = Vector3.new(100000,100000,100000) -- can mess with this or the 80's
			bv.Velocity = (Char.Head.CFrame.LookVector * -80)
				+ (Char.Head.CFrame.UpVector * 80)
			task.wait(0.01) bv:Destroy()
			db = false
		end	task.wait(1)
	end
end)

What’s this

local pushForce = 100
local d = false

script.Parent.Touched:Connect(function(part)
	if part.Parent.Head.Material == Enum.Material.Granite then
		local humanoid = part.Parent:FindFirstChild("Humanoid")
			if humanoid and d == false then
			d = true
			script.Parent.Ouch.PlaybackSpeed = math.random(7,11) * 0.1
			script.Parent.Ouch:Play()
			script.Parent.Parent.Zombie.Health = script.Parent.Parent.Zombie.Health - 10
			local character = humanoid.Parent
			local bodyVelocity = Instance.new("BodyVelocity")
			bodyVelocity.Velocity = (part.Position - character.Torso.Position).unit * pushForce
			bodyVelocity.P = math.huge
			bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bodyVelocity.Parent = character.Torso
			wait(0.5) 
			bodyVelocity:Destroy()
			d = false
		end
	end
end)

I’m sorry is that not what you wanted?

1 Like

Yes, i want it to push the sphere that you control straight.

1 Like
local pushForce = 500 -- Adjust this value to change the strength of the push

local function onTouched(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local character = humanoid.Parent
        local rootPart = character:FindFirstChild("HumanoidRootPart")
        if rootPart then
            local bodyVelocity = Instance.new("BodyVelocity")
            bodyVelocity.Velocity = rootPart.CFrame.LookVector * pushForce
            bodyVelocity.P = math.huge
            bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
            bodyVelocity.Parent = rootPart

            -- Remove the body velocity after a certain amount of time
            wait(0.1) -- Adjust the duration as needed
            bodyVelocity:Destroy()
        end
    end
end

script.Parent.Touched:Connect(onTouched)
1 Like

The sphere that you control has only two parts: The head and the torso.

1 Like
local pushForce = 500 -- Adjust this value to change the strength of the push

local function onTouched(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local character = humanoid.Parent
        local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
        local head = character:FindFirstChild("Head")
        if torso and head then
            local direction = (part.Position - torso.Position).unit
            local pushVector = (direction + Vector3.new(0, 1, 0)).unit * pushForce
            torso.Velocity = pushVector
            head.Velocity = pushVector

            -- Remove the velocity after a certain amount of time
            wait(0.1) -- Adjust the duration as needed
            torso.Velocity = Vector3.new(0, 0, 0)
            head.Velocity = Vector3.new(0, 0, 0)
        end
    end
end

script.Parent.Touched:Connect(onTouched)
3 Likes

Thanks so much for solving. Works now.

1 Like

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