Why doesn't this code work when I Index the variable like this?

Heyo, quick question.

Why does this work perfectly fine:

local Blur = game.Lighting.UIBlur -- Variable doesn't define the Enabled property

function leftClick()
	Blur.Enabled = true -- Enabled property is indexed on this line
end

script.Parent.MouseButton1Click:Connect(leftClick)

But this doesn’t work:
Also, it doesn’t produce any errors in the console?

local Blur = game.Lighting.UIBlur.Enabled -- The Enabled property is defined in the variable 

function leftClick()
	Blur = true 
end

script.Parent.MouseButton1Click:Connect(leftClick)

Aren’t they the same just defined differently?

Yet this works perfectly?

local Count1 = game.ServerStorage:WaitForChild("Count") 
local Count2 = game.ServerStorage:WaitForChild("Count").Value -- The Value property is defined in the variable here for Count2

print(Count1.Value)  -- The Value property is defined in the variable here for Count1
print(Count2)

Below I linked a game file containing this example
Example.rbxl (33.2 KB)

1 Like

This returns the value of ‘Enabled’, which means you can’t modify it because it’s only something that was returned. Think of it as read-only.

2 Likes

Why doesn’t local Count2 = game.ServerStorage:WaitForChild("Count").Value return the value of the IntValue’s ‘Value’ property?

It does. [Character limits are silly]

Why isn’t it treated in the same way?

You are taking a copy of the current value in an object. Indexing object’s values do not have pointers to change them again. (like some other programming languages iirc? and also tables and arrays in luau)

1 Like