Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make my projectile only explode when it hits a player?

I would like to know how to make my projectile explode when it touches PLAYERS. Whenever I use it, it explodes when touching ANYTHING. Please help :D <3 btw I have another script adding the velocity and such just so you all know :D

local part = game.Workspace.BallEx
part.Transparency = 0.3

local fire = Instance.new("Fire")
		fire.Color = Color3.new(108, 91, 236)
		fire.SecondaryColor = Color3.new(104, 0, 139)
		fire.Heat = 25
		fire.Size = 30
		fire.Parent = part
		
part.Touched:Connect(function()
	
	local explosion = Instance.new("Explosion")
		explosion.BlastPressure = 50000
		explosion.BlastRadius = 10
		explosion.Parent = game.Workspace
		explosion.Position = part.Position
	part:Destroy()
end)

1 answer

✓ Accepted answer
local part = game.Workspace.BallEx
part.Transparency = 0.3

local fire = Instance.new("Fire")
        fire.Color = Color3.new(108, 91, 236)
        fire.SecondaryColor = Color3.new(104, 0, 139)
        fire.Heat = 25
        fire.Size = 30
        fire.Parent = part

part.Touched:Connect(function(Touched)
	if Touched.Parent:FindFirstChild("Humanoid") then
   		local explosion = Instance.new("Explosion")
       		explosion.BlastPressure = 50000
       		explosion.BlastRadius = 10
       		explosion.Parent = game.Workspace
       		explosion.Position = part.Position
		part:Destroy()
	end
end)

This checks to see if there is a humanoid inside of the parent of the object it hits, which all players have.

1 comment

0

TYSM! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.