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

Part won't show up?[ANSWERED]

Asked by 9 years ago

I'm making an activation tycoon, but the activation is irrelevant for this question.

01local dp = script.Parent:FindFirstChild("DropPart")
02local b = script.Parent:FindFirstChild("Button")
03print("1st print")
04local debounce = false
05 
06if 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
View all 26 lines...

I've checked the hierachy and everything is fine. When I click the button, nothing happens.

0
Also if you're wondering i'm adding the whole cash part later connieoop 10 — 9y

2 answers

Log in to vote
0
Answered by
funyun 958 Moderation Voter
9 years ago

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 
03local 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.
04local b = script.Parent:WaitForChild("Button")
05local c = b:WaitForChild("ClickDetector")
06debounce = false
07 
08function 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 = Vector3.new(1,1,1)
15        p.Parent = script.Parent:FindFirstChild("PartStorage")
View all 24 lines...
0
Thank you!!! connieoop 10 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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

01local dp = script.Parent:FindFirstChild("DropPart")
02local b = script.Parent:FindFirstChild("Button")
03local c = b:FindFirstChild("ClickDetector")
04debounce = false
05 
06c.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 = Vector3.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
20end)

Answer this question