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