Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

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

0

No. That’s literally all there is

3 answers

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)

1 comment

0

Color3 uses RGB Brickcolor uses those default ones.

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)
ClickDetector.MouseClick:Connect(OnClick())

You are missing a set of brackets.

6 comments

0

Nope. I’m pretty sure it will give me an error if I add them in

0

what line is the error on?

0

I dont see why adding it in a click detector would break things if it works outside of the click detector function.

0

Line 6. Me either, I’m so confused on why it doesn’t work

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.

0

This isn't how you write connections...

This discussion is preserved as it was. New answers, comments, and votes are closed.