0

# "Attempt to call a table value" when changing a part's color on click?

1uqt 2
19 days ago

My code is hooked up to a button that's supposed to change a part's color when clicked. But when its clicked, it just keeps giving me the error "attempt to call a table value". I've even tried the code by itself, and it works perfectly. So I don't really understand what's going on.

local ClickDetector = script.Parent:FindFirstChild("ClickDetector")
function OnClick()
for i,v in pairs(workspace.Baseplate:GetChildren()) do
if v:IsA("Part") and v.Name == "Door" then
v.BrickColor = BrickColor.new("Medium stone grey")
end
end
end

ClickDetector.MouseClick:Connect(OnClick)

0
I took your script and placed it in a test baseplate and it worked fine without any errors. its probably something before the script you gave that caused the issue Hypoxla 125 — 19d
0
No. That’s literally all there is 1uqt 2 — 18d

0
Edited 18 days ago

idk, try this:

local ClickDetector = script.Parent:FindFirstChild("ClickDetector")
function OnClick()
for i,v in pairs(workspace.Baseplate:GetChildren()) do
if v:IsA("Part") and v.Name == "Door" then
v.Color3 = BrickColor.new("Medium stone grey").Color
end
end
end

ClickDetector.MouseClick:Connect(OnClick)

0
Color3 uses RGB Brickcolor uses those default ones. manith513 61 — 18d
0
1uqt 2
18 days ago
Edited 18 days ago

SOLUTION: Instead of changing the actual BrickColor, I just used RGB values and it works perfectly.

local ClickDetector = script.Parent:FindFirstChild("ClickDetector")
function OnClick()
for i,v in pairs(workspace.Baseplate:GetChildren()) do
if v:IsA("Part") and v.Name == "Door" then
v.Color = Color3.fromRGB(163, 162, 165)
end
end
end

ClickDetector.MouseClick:Connect(OnClick)

-1
ClickDetector.MouseClick:Connect(OnClick())



You are missing a set of brackets.

0
Nope. I’m pretty sure it will give me an error if I add them in 1uqt 2 — 19d
0
what line is the error on? manith513 61 — 19d
0
I dont see why adding it in a click detector would break things if it works outside of the click detector function. manith513 61 — 19d
0
Line 6. Me either, I’m so confused on why it doesn’t work 1uqt 2 — 19d