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

Exploding Barrel using clickdetectors but it doesn't work?

I'm trying to make a exploding barrel for my game but for it in order to explode it needs to be click but it doesn't work when i try it.Any help?

Script:

script.Parent.mouseClick:connect(function()
	local explosionPart = script.Parent
	local explosion = Instance.new("Explosion" , game.Workspace)
	explosion.Position = explosionPart.Position
    explosionPart:Destroy()	
end)

1 comment

0

You can use code block to write script

2 answers

The problem is that there's no such event as "mouseClick". Keep in mind that in lua everything is case sensitive. Also you should add a "ClickDetector" into the part, because parts don't have the event "MouseClick" which is needed in this case. Here's what your script should look like.

local ClickDetector = Instance.new("ClickDetector", script.Parent)

ClickDetector.MouseClick:connect(function(playerWhoClicked) 
	local explosionPart = script.Parent 
	local explosion = Instance.new("Explosion" , game.Workspace) 
	explosion.Position = explosionPart.Position 
	explosionPart:Destroy() 
end)

1 comment

0

Sadly it still doesn't explode,Is there something I'm doing wrong or do I have to put in the Explosion thing into my model?

Parts don't have a mouseclick. You have to put a clickdetector inside of the part first and the change script.Parent.mouseClick to script.Parent.ClickDetector.MouseClick

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