Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Part won't show up?[ANSWERED]

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.

1 comment

0

Also if you're wondering i'm adding the whole cash part later

2 answers

✓ Accepted answer

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.

1 comment

0

Thank you!!!

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.