I'm making an activation tycoon, but the activation is irrelevant for this question.
01 | local dp = script.Parent:FindFirstChild( "DropPart" ) |
02 | local b = script.Parent:FindFirstChild( "Button" ) |
03 | print ( "1st print" ) |
04 | local debounce = false |
05 |
06 | if b and dp then |
07 | print ( "First IF" ) |
08 | local c = b:FindFirstChild( "ClickDetector" ) |
09 | if c.MouseClick and debounce = = false then |
10 | debounce = true |
11 | print ( "Debounce" ) |
12 | b.BrickColor = BrickColor.Red() |
13 | local p = Instance.new( "Part" ) |
14 | print ( "Creating part" ) |
15 | p.CFrame = dp.CFrame |
I've checked the hierachy and everything is fine. When I click the button, nothing happens.
You're using "c.MouseClick" like it's a condition, when in fact it is an event. Events are connected to functions with event:connect(function)
.
01 | --First of all, I recommend letting Lua tab your script out, only adding tabs when it's not doing what you want it to do. |
02 |
03 | local dp = script.Parent:WaitForChild( "DropPart" ) --Don't use FindFirstChild, or the script might continue, not knowing what DropPart is. Use WaitForChild to wait for objects to load. |
04 | local b = script.Parent:WaitForChild( "Button" ) |
05 | local c = b:WaitForChild( "ClickDetector" ) |
06 | debounce = false |
07 |
08 | function onMouseClick() |
09 | if debounce = = false then |
10 | debounce = true |
11 | b.BrickColor = BrickColor.Red() |
12 | local p = Instance.new( "Part" ) |
13 | p.CFrame = dp.CFrame |
14 | p.Size = Vector 3. new( 1 , 1 , 1 ) |
15 | p.Parent = script.Parent:FindFirstChild( "PartStorage" ) |
The problem is that you don't have a function for MouseClick so the script won't do anything when the button is clicked. You will need a function to do this
01 | local dp = script.Parent:FindFirstChild( "DropPart" ) |
02 | local b = script.Parent:FindFirstChild( "Button" ) |
03 | local c = b:FindFirstChild( "ClickDetector" ) |
04 | debounce = false |
05 |
06 | c.MouseClick:connect( function () |
07 | if not debounce then |
08 | debounce = true |
09 | b.BrickColor = BrickColor.Red() |
10 | local p = Instance.new( "Part" ) |
11 | p.CFrame = dp.CFrame |
12 | p.Size = Vector 3. new( 1 , 1 , 1 ) |
13 | p.Parent = script.Parent:FindFirstChild( "PartStorage" ) |
14 | wait( 5 ) |
15 | b.BrickColor = BrickColor.Green() |
16 | wait( 5 ) |
17 | p:Destroy() |
18 | debounce = false |
19 | end |
20 | end ) |