Button1 is not a valid member of Model "Workspace.Tube"

Hello! I am trying to make a script where if you click something it typewrites it on a GUI!

Unfortunatly, everytime when I load in the game this error pops up and clicking on the button does nothing.

Here is my code and I am really confused and have NO IDEA why it’s appearing when I load in the game and not when I click.

local function typewrite(textlabel,text)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		game.Workspace.textsfx:Play()
		wait(0.05)
	end
end

local enabled = true
local part = game.Workspace.Tube.Button1.ClickDetector

part.MouseClick:Connect(function(plr)
	local textlabel = game.Players.LocalPlayer.PlayerGui.Text.Message
	if enabled == true then
		local enabled = false
		typewrite(textlabel, plr.Name.. ", this is the text that will appear when I click!")
		wait(7)
	end
end)

Thank you all!

Can you send a screenshot of the explorer including the ClickDetector?

Of course!

The error appears when you load in and not when you click, because the error stems from

local part = game.Workspace.Tube.Button1.ClickDetector

Which comes before the click detecting function. Since it is not waiting for any input or event, it activates when the game runs.

Does Button1 start parented to Tube? If not, you need to either make sure that it is, or that the function waits until it is (using WaitForChild())

Thank you very much it has worked by making it wait for child!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.