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

how do i add on touched to this script it explodes without getting touched?

while wait(1) do
	local EX = Instance.new("Explosion")
	EX.DestroyJointRadiusPercent = 0
	EX.Parent = script.Parent
	EX.Position = script.Parent.Position
	EX.BlastPressure = 1
	EX.BlastRadius = 5
	EX.Hit:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") ~= nil then
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(2)
		end
	end)
	
end

it explodes without getting touched but i want it to explode on touch how do i do that

1 answer

Assuming the parent of the script is a part then a very simple way of doing it would be:

script.Parent.Touched:Connect(function(hit)
	if hit ~= game.Workspace then   -- the ~= means "Does not equal"
		local EX = Instance.new("Explosion")
		EX.DestroyJointRadiusPercent = 0
		EX.Position = script.Parent.Position
		EX.BlastPressure = 1
		EX.BlastRadius = 5

		EX.Parent = script.Parent
		--Setting the parent of an explosion to a part in the workspace will set th explosion to go off immediatly, and then delete itself after it is finished

	end
end)

I apologize if this script doesnt work but it should in theory.

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