Well, I'm still learning my way around lua. So, I made a part that would explode if clicked, inside the part is a click detector, and inside the click detector is a script.
However, when clicked, the said part doesn't explode.
Here's the code:
if script.Parent clicked = true then create:Explosion explosion Radius = 15 explosion BLAST_PRESSURE = 2*10^6 end
Any help? Thanks!
script.Parent.MouseClick:Connect(function() -- wait until the part is clicked local Explotion = `Instance.new`("Explosion") --Create a new instance Explotion.BlastRadius = 15 -- Setting its properties Explotion.BlastPressure = 2 * math.pow(10,6) --Setting properties. You can also use math.pow instead of x^y Explotion.Position = script.Parent.Parent.Position --Set the position of the explotion. Explotion.Parent = script.Parent.Parent --Set the parent of the explotion. In this case It's the part. end)
Hi. I want to point out that the clickdetector has events that fires when certain conditions are met. For example if the player clicks or right-clicks. And, usually after that, the event is connected to a fucntion like so:
Event:Connect(function() --Lines of code end)
But you can also do them like this:
function OnPartTouched() --lines of code end script.Parent.MouseClick:Connect(OnPartTouched)
To create a new instance you use Instance.new(Class, Parent of class)
. You want to specify your class in the first parameter of instance.new BUT note that the second parameter, which allows you to set the parent of the object is deprecated and can cause performance issues. So it's preferable to set the parent of the object after you've declared it..