Putting an Explosion instance into every player

  1. What do you want to achieve?
    I would like to make a system where if a player, lets say touches a part, every other player explodes using Instance.new(“Explosion”)

  2. What is the issue?
    I am unable to figure out a way to make it so that there is an explosion instance in each player

  3. What solutions have you tried so far?
    I havent came any solution that could help me with this issue.

I know how to use Instance.new(“Explosion”) but not in a way like this. If this is even possible

local Part = script.Parent
local Players = game:GetService("Players")

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		for _, player in pairs(Players:GetPlayers()) do
			if player.Parent and not player.Character:FindFirstChild("PartExplosion") then
				local Character = player.Character or player.CharacterAdded:Wait()
				local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
				local Explosion = Instance.new("Explosion")
				Explosion.Name = "PartExplosion"
				Explosion.BlastRadius = 20
				Explosion.ExplosionType = Enum.ExplosionType.Craters -- damages terrain
				Explosion.Position = HumanoidRootPart.Position
				Explosion.Parent = Character
			end
		end
	end
end)

Put this inside your part and you should be good to go!

Here is the place if you are having trouble setting up:
explosionpart.rbxl (41.9 KB)

1 Like

So, in a ServerScript, when the part is touched, you will get the hit part, which you’ll use to get the player, to avoid them exploding, you can remove this if you want.
You then loop through all the players, and if the player ~= you then you create an explosion.

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and game.Players:GetPlayerFromCharacter(hit.Parent) then
local HitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
for _, player in pairs(game.Players:GetPlayers()) do
-- Make other players explode, and you yourself not explode
if player.Character and player ~= HitPlayer then
local Explosion = Instance.new(“Explosion”, player.Character)
end
end
end
end
1 Like
 local deb = false
script.Parent.Touched:Connect(function(hit)
	if deb == false then
		deb = true
	local h = hit.Parent:FindFirstChildOfClass("Humanoid") 
	
	if h then
		for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
					local char = plr.Character
			local explosion = Instance.new("Explosion", char)
				explosion.Position = char.HumanoidRootPart.Position
		end
		end
	wait(1)
		deb = false
	end
end)
1 Like

both this and @TheSpecialNone’s solution work wonderfully! thanks for the help :DD

1 Like