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

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

Asked by
1uqt 2
2 years 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 — 2y
0
No. That’s literally all there is 1uqt 2 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years 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 121 — 2y
Ad
Log in to vote
0
Answered by
1uqt 2
2 years ago
Edited 2 years 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)
Log in to vote
-1
Answered by
manith513 121
2 years ago
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 — 2y
0
what line is the error on? manith513 121 — 2y
0
I dont see why adding it in a click detector would break things if it works outside of the click detector function. manith513 121 — 2y
0
Line 6. Me either, I’m so confused on why it doesn’t work 1uqt 2 — 2y
View all comments (2 more)
0
There shouldnt be an error on a normal end? what is before and after your script thats the only other reason why it's bugging. manith513 121 — 2y
0
This isn't how you write connections... Kingu_Criminal 205 — 2y

Answer this question