Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Explosion but without the explosion?

Asked by 4 years ago

im not really asking for scripts but if you could tell me how to make a script so then i can step on a landmine but instead of the explosion visuals i get the particle explosion that i have working but still have the power of the explosion to fling me and kill me

0
explosion.BlastPressure! User#23252 26 — 4y
0
oHhhhhhhhhhh ok thank you supersoli12345 6 — 4y

1 answer

Log in to vote
0
Answered by
Yuuwa0519 197
4 years ago

I am not so confident with what I came up, but I will share it anyways.

Step1. Go through every player close to that landmine when someone steps on it, and return the magnitude like this:

local Players = game:GetService("Players")
local function explode(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    for i,v in pairs(Players:GetPlayers()) do
        if v.Characer then
            local humRoot = v.Character:FindFirstChild("HumanoidRootPart")
            if humRoot then
                local distance = (script.Parent.Position - humRoot.Position).magnitude
            end
        end
    end
end

script.Parent.Touched:Connect(explode)

Step2. Determine whether to kill player, by comparing the distance to the value of how close the player should be to get killed. and if not kill, fling the character by using the body force.

local Players = game:GetService("Players")
local maxDist = 100
local killDist = 20
local function explode(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    for i,v in pairs(Players:GetPlayers()) do
        if v.Character then
            local character = v.Character
            local humRoot = v.Character:FindFirstChild("HumanoidRootPart")
            if humRoot then
                local distance = (script.Parent.Position - humRoot.Position).magnitude
                local Humanoid = character:FindFirstChild("Humanoid")
                if distance < killDist then
                    --Kills player
                    if Humanoid then
                        Humanoid:TakeDamage(100--[[Damage Player]])
                    end
                elseif distance < maxDist then
                    --won't kill, but will fling            
                    local BF = Instance.new("BodyForce")
                    BF.Force = Vector3.new(math.random(-1000,1000),10000,math.random(-1000,1000)) --Flings in random direction
                    Humanoid.Sit = true
                    BF.Parent = humRoot
                    game:GetService("Debris"):addItem(BF,.1)
                end
            end
        end
    end
end
script.Parent.Touched:Connect(explode)
Ad

Answer this question