Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this into a simple click dectector?

Asked by 5 years ago

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 : )

0
Can you please update this question into the code block format? It's stressful to read like this. Warriorfoox 25 — 5y
0
I don't know how to do that, could you tell me how? girlthing1234 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited by User#24403 5 years ago

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

0
Or maybe don't reinvent the wheel and just use player.Character... User#24403 69 — 5y
0
It worked thank you! girlthing1234 2 — 5y
0
I'll explain my goal with this girlthing1234 2 — 5y
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 girlthing1234 2 — 5y
Ad

Answer this question