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)
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)
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.