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

Why is it telling me TextLabel is not a valid member of ImageButton?

local player = game.Players.LocalPlayer
local txt = script.Parent.TextLabel
local Frame = script.Parent.Parent


script.Parent.MouseButton1Click:connect(function()
	
	if txt.Visible == true then
		txt.Visible = false
	else if txt.Visible == false then
		txt.Visible = true
	end
	end
end)

Textlabel is inside ImageButton, but its not a valid member of it? WHAT?

1 answer

✓ Accepted answer

If this helps, please be sure to accept my answer.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- we add this to wait for the player's character to be added in workspace.
local txt = script.Parent:WaitForChild('TextLabel') -- Use WaitForChild so it can wai for the child to be added.
local Frame = script.Parent.Parent


script.Parent.MouseButton1Click:connect(function()
    if txt.Visible == true then
        txt.Visible = false
    elseif txt.Visible == false then -- DON'T leave a space between "else" and "if".
        txt.Visible = true
    end
	--you had an extra "end" here. I remved it though. We don't need one here because you are not ending a scope.
end)

2 comments

0

The problem was "TextLabel" was basically nil and it couldn't find it or something because after I put in waitforchild "textlabel" it worked. Thanks!

0

Yes, I would recommend adding everything in my code I sent you to put in yours.

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