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

Exploding Barrel using clickdetectors but it doesn't work?

Asked by 5 years ago
Edited 5 years ago

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)
0
You can use code block to write script marijus06 68 — 5y

2 answers

Log in to vote
0
Answered by
luachef 61
5 years ago
Edited 5 years ago

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)
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? rochel89 42 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question