I am trying to make a can that players can drop red items into. Players should be able to drop their red item into the can (via ProximityPrompt). Then the can’s overhead gui should update to show how many red items are inside.
However, when I run the game, I get an error in the output saying that “BrickColor is not a valid member of Part” (The error is from line 10 and the red items consist of a part named “Handle” inside a tool).
I’ve tried switching between BrickColor and Color3, but nothing is working so far.
Here’s my code:
local RedCount = 0 --Keeps track of how many red studs are inside the can.
local RedPrompt = script.Parent.RedCan.Base.ProximityPrompt
local function Add1(Player)
local Check = Player.Backpack:FindFirstChild("Stud") --Checks if a red stud is in the player's backpack.
if Check ~= nil then
if Player.Backpack.Stud.Handle.BrickColor == BrickColor.new("Bright red") then
local Material = Player.Backpack:WaitForChild("Stud")
Material:Destroy()
RedCount = RedCount + 1
script.Parent.RedCan.BillboardGui.TextLabel.Text = "Red - "..RedCount --Updates text.
end
end
local Check2 = Player.Character:FindFirstChild("Stud") --Checks if player is holding a red stud.
if Check2 ~= nil then
if Player.Character.Stud.Handle.Color3 == Color3.new(0.768627, 0.156863, 0.109804) then
local Material = Player.Character:WaitForChild("Stud")
Material:Destroy()
RedCount = RedCount + 1
script.Parent.RedCan.BillboardGui.TextLabel.Text = "Red - "..RedCount --Updates text.
end
end
end
RedPrompt.Triggered:Connect(Add1) --[[Adds +1 to RedCount and updates the can's text when
a player is holding a red stud when they click the prompt]]
(=> this is my first post so I’m hoping I did everything right)