Attempt to index nil with 'Connect'

  1. An event that fires you click the button. It’s function is to print “Hello world” (I am just keeping it simple and clear, But the real function after the Event works is to change a textlabel Property)

  2. When I start the game it tell’s me "Players.mustafahhh.PlayerGui.FontsUi.Frame.TextButton.LocalScript:10: attempt to index nil with ‘Connect’"

  3. I tried to change the event, I tried to search at Developer hub. But I didn’t find solution so far

local Button = script.Parent 

Button.Activated:Connect(function()
 print('hello world')
end)

I will say it twice so you don’t miss understand. This is the not real function of this Event. But this is the most basic and simple thing I can so you understand where’s the problem. So you don’t get confused

Try MouseButton1Click instead of Activated.

Button seems to be nil, are you sure that you’re properly checking for a UIObject? It’s either that or

You have to remove the :robux_gold: thing which is why it also results as an error

Quite clearly this error you are seeing is performed by another script. This script does not reference ‘Connect’ nor does it even have a 10th line

I put the :roblox_gold: accidentally while writing the topic
But it doesn’t exist’s on the real code at roblox studio

Yup. I tried to use MouseButton1Click and other Events

Uhhh, this is how the code look like in Roblox studio, I just made it more basic above
image

But after I deleted Other Useless lines. It didn’t give me the errors somehow

You re-defined Button as a string

image

Strings don’t even have Events :thinking: Unless if you meant to call FindFirstChild() to check for that exact Name of the Button

local TextScaled = script.Parent.Parent.Parent.Text.TextScaled --?
local Button = script.Parent
local ButtonCheck = TextScaled:FindFirstChild(Button.Name)

if ButtonCheck then
    ButtonCheck.Activated:Connect(function()
        print("Hello world")
    end)
end
1 Like

Ohhhh. Now I understand what really happened, I didn’t used Roblox studio for long time. That is why this happened I think. Thanks for helping me