When I touch the part, my body does not explode.
--Make players heads explode when touched part leftleg = game.Workspace.Player:GetChildren() explosion = Instance.new("Explosion") function onTouched(player) player.leftleg = explosion end script.Parent.Touched:connect(onTouched)
function onTouch(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then local Char = hit.Parent local explosion = Instance.new("Explosion", Char.Head) explosion.Position = Char.Head.Position end end script.Parent.Touched:connect(onTouch)
Checks if what touched the Part is indeed a Player's character, then Instances an explosion into that character's head.
I have no idea how to do explosions though.
So what we would first do is make the function.
function explode(part) end
Now we will make a variable to access the torso.
local torso = part.Parent:FindFirstChild("Torso')
We now need to make sure that Torso actually exists, using if ~= nil then
.
if torso ~= nil then
Now we do the explosions.
local explosion = Instance.new("Explosion") explosion.Parent = torso explosion.Position = torso.Position
The Finished Script
function explode(part) local torso = part.Parent:FindFirstChild("Torso') if torso ~= nil then local explosion = Instance.new("Explosion") explosion.Parent = torso explosion.Position = torso.Position end end
We do not need to worry about the health, because the explosion will kill them anyways.
Please accept if helped.
Thank you.