Throw player away after explosion

Hello folks, I’m working on a script for a mine, where when the player steps on the mine, it explodes. However, I want the mine to throw the player away to make it even better. Can you help me?

local vfx = script.Parent:FindFirstChild("VFX")
local hasExploded = false

function ActivateVFX()
    if vfx then
        for _, child in ipairs(vfx:GetChildren()) do
            if child:IsA("ParticleEmitter") then
                child:Emit(20)
            end
        end
    end
end

function OnTouch(hit)
    if hasExploded then return end

    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if humanoid and humanoid:IsA("Humanoid") and hasExploded == false then
        hasExploded = true
        script.Parent.Click:Play()
        wait(0.2)
        script.Parent.ExplosionSound:Play()
        ActivateVFX()

        humanoid:TakeDamage(500)

        script.Parent.Transparency = 1
        script.Parent.CanCollide = false

        wait(20)

        hasExploded = false
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true
    end
end

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

What do you mean by “throw the player away”? Do you mean like literally after the explosion happens you want the player to fling or like have them get thrown into a trash can?

I am assuming that you want something like BodyVelocity! It will send the player where u set the Velocity. Only downfall is that, BodyVelocity is not recommended and is replaced by LinearVelocity. Practically the same thing, but requires an Attachment. Note: If you are using Custom Characters, make sure they got an Attachment in the PrimaryPart(If you use Linear Velocity).
After choosing one, what you wanna do is make one(Linear or Body) and put it into the Players PrimaryPart. Make sure to set the Vector/Velocity Value to the (player - mine).Unit Vector(This will give the direction to fling the player in). As well the MaxForce will need to be increased for more Power!

Long Story Short

You want something like this:

local bv = Instance.new("LinearVelocity",plr.Character.HumanoidRootPart)
bv.MaxForce = 999999
bv.Attachment0 = plr.Character.HumanoidRootPart:FindFirstChildWhichIsA("Attachment")
bv.LineVelocity = (plr.Character.HumanoidRootPart.Position - script.Parent.Position).Unit * 80 + Vector3.new(0,20,0)
game.Debris:AddItem(bv,.2)

Times the Unit(0,0,1) by Distance(80) and Adds 20 to Y(height/sends player upward) =
Vector3(0,20,80)

BodyVelocity
local bv = Instance.new("BodyVelocity",plr.Character.HumanoidRootPart)
bv.MaxForce = Vector3.one * 999999
bv.Velocity = (plr.Character.HumanoidRootPart.Position - script.Parent.Position).Unit * 80 + Vector3.new(0,20,0)
game.Debris:AddItem(bv,.2)
2 Likes

A script to toss the player back … inside a part (mine for you)

-- SeverScript

local bv, char
local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db then db = false char = hit.Parent
			bv = Instance.new("BodyVelocity")
			bv.Parent = (char.Head)
			bv.MaxForce = Vector3.new(100000,100000,100000)
			bv.Velocity = (char.Head.CFrame.LookVector * -80)
				+ (char.Head.CFrame.UpVector * 80)
			wait(0.01) bv:Destroy()
			db = true
		end
	end
end)
1 Like