I would like for the player to explode upon the part being touched by said player.
So far, I have not found any solutions and I have been looking on the hub and such.
Basically, I am just trying to mess around with a few things out of pure boredom. One of which was because of a comment someone had made on Discord mentioning something about a metal playground slide that’d been sitting out during the summer. I wanted to post a video in response simply to kind of mess around with them.
Here’s an example code, it should achieve what you want.
local function byebyePlayer(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
local Explosion = Instance.new("Explosion", workspace)
Explosion.Position = hit.Parent.HumanoidRootPart.Position
end
end
workspace.Part.Touched:Connect(byebyePlayer)
You could use the .touched event and this way to make a custom explosion or to simplify things u could just do Instance.new(“Explosion”)
local partToTouch = path
local explosionRange = 15
local explosionDamage = 10
function Explode()
local attachment = Instance.new("Attachment")
attachment.Position = partToTouch.Position
attachment.Parent = workspace.Terrain
local hit = {}
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") then
if (v.Position-attachment.Position).Magnitude < explosionRange and not hit[v] then
hit[v] = true
v:FindFirstChildOfClass("Humanoid"):TakeDamage(explosionDamage)
--knockback
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(15000,15000,15000)
bv.Velocity = (v.Position-attachment.Position).Unit*30+Vector3.new(0,math.random(10,15),0)
bv.Parent = v
game.Debris:AddItem(bv,.5)
end
end
end
attachment:Destroy()
end
end
partToTouch.Touched:Connect(function(touched)--touched
if touched and touched.Parent then
if touched.Parent:FindFirstChildOfClass("Humanoid") and touched.Parent:FindFirstChild("HumanoidRootPart") then --if it contains the basics of a player
Explode()
partToTouch:Destroy()
end
end
end)
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
local Explosion = Instance.new("Explosion")
Explosion.Parent = script.Parent
Explosion.Position = script.Parent.Position
end
end)
local part = script.Parent
part.Touched:Connect(function(hit)
local hitModel = hit:FindFirstAncestorOfClass("Model")
if not hitModel then return end
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if not hitPlayer then return end
local explosion = Instance.new("Explosion")
explosion.Parent = part
end)
local part = script.Parent
part.Touched:Connect(function(hit)
local hitModel = hit:FindFirstAncestorOfClass("Model")
if not hitModel then return end
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if not hitPlayer then return end
local explosion = Instance.new("Explosion")
explosion.Parent = part
end)