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

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

Asked by 7 years ago
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

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
7 years ago

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)
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! GuestRealization 102 — 7y
0
Yes, I would recommend adding everything in my code I sent you to put in yours. FiredDusk 1466 — 7y
Ad

Answer this question