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 8 years ago

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



local dp = script.Parent:FindFirstChild("DropPart") local b = script.Parent:FindFirstChild("Button") print("1st print") local debounce = false if b and dp then print("First IF") local c = b:FindFirstChild("ClickDetector") if c.MouseClick and debounce == false then debounce = true print("Debounce") b.BrickColor = BrickColor.Red() local p = Instance.new("Part") print("Creating part") p.CFrame = dp.CFrame p.Size = Vector3.new(1,1,1) print("Set size and postition") p.Parent = script.Parent:FindFirstChild("PartStorage") wait(5) b.BrickColor = BrickColor.Green() print("Set Brick Color") wait(5) p:Destroy() print("Destroyed Part") end end

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 — 8y

2 answers

Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 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).

--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.

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.
local b = script.Parent:WaitForChild("Button")
local c = b:WaitForChild("ClickDetector")
debounce = false

function onMouseClick()
    if debounce == false then
        debounce = true
        b.BrickColor = BrickColor.Red()
        local p = Instance.new("Part")
        p.CFrame = dp.CFrame
        p.Size = Vector3.new(1,1,1)
        p.Parent = script.Parent:FindFirstChild("PartStorage")
        wait(5)
        b.BrickColor = BrickColor.Green()
        wait(5)
        p:Destroy()
        debounce = false --So we can click again when everything's done. I don't know if you meant to put this and forgot about it, or you intentionally didn't put it there.
    end
end

c.MouseClick:connect(onMouseClick) --See? Connecting events to functions.
0
Thank you!!! connieoop 10 — 8y
Ad
Log in to vote
0
Answered by 8 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

local dp = script.Parent:FindFirstChild("DropPart")
local b = script.Parent:FindFirstChild("Button")
local c = b:FindFirstChild("ClickDetector")
debounce = false

c.MouseClick:connect(function()
    if not debounce then
        debounce = true
        b.BrickColor = BrickColor.Red()
        local p = Instance.new("Part")
        p.CFrame = dp.CFrame
        p.Size = Vector3.new(1,1,1)
        p.Parent = script.Parent:FindFirstChild("PartStorage")
        wait(5)
        b.BrickColor = BrickColor.Green()
        wait(5)
        p:Destroy()
        debounce = false
    end
end)

Answer this question