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

How can I make this into a simple click dectector?

local debounce = false

script.Parent.Touched:Connect(function(hit) if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) and debounce == false then debounce = true local Explosion = Instance.new("Explosion") Explosion.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position Explosion.Parent = hit.Parent:FindFirstChild("HumanoidRootPart") script.BOOM:Play() wait(3) debounce = false end end)

I want a part to be clicked to activate the explosion and sound thank you if you helped : )

2 comments

0

Can you please update this question into the code block format? It's stressful to read like this.

0

I don't know how to do that, could you tell me how?

1 answer

✓ Accepted answer

The code block below will be the script for this and if you want an explanation, it will be below the code block.

-- make a part with a click detector and a script as its child.

local debounce = false

script.Parent.MouseButton1Click:Connect(function(player)
	if not debounce then
		debounce = true
		local Explosion = Instance.new("Explosion")
		Explosion.Parent = workspace
		Explosion.Position = player.Character.HumanoidRootPart.Position
		script.Boom:Play() -- also add the sound as a child of the script.
		wait(3)
		debounce = false
	end	
end)

The listeners of MouseClick get the player who clicked the part as an argument, similar to how Touched event listeners get the part that touched.

If you have any questions feel free to leave a comment and I'll answer it ASAP

4 comments

0

Or maybe don't reinvent the wheel and just use player.Character...

0

It worked thank you!

0

I'll explain my goal with this

0

So I want to make a character to have a bomb on it that explodes on command, with clicking it or any other way, I just discovered I can't have a click dectector on a StarterCharacter, So how would I go on about of doing that? Sorry if I'm bugging this is my first post asking for help I've been learning scripting for a few months now but it's hard with all the scattered information

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