Changing a parts value when player leaves

Basically I have a folder named “Paintable” with parts in it. The parts have values in them and one of those Values is named “Holder”. The value of holder is the players name who owns that part.

The script is supposed to check all parts for The StringValue named “Holder” and check if the value inside is equal to the player who left.

Code:

Players.PlayerRemoving:Connect(function(player)
	local Folder = PlacedItems:FindFirstChild(player.Name)
	Folder:Destroy()
	
	for _,v in pairs(game.Workspace.Paintable:GetDescendants()) do
		if v:IsA("StringValue") and v.Value == player.Name then
			v.ClickDetector:Destroy()
			v.Paintable.Value = true
				v.BrickColor = BrickColor.new("Dark stone grey")
		end
	end
	
end)

There is no error popping up.
image

(Yes I know there is no clickdetector inside of it because I have not claimed the part yet)

SOLUTION EDIT:
Heres the fixed code in case you were wondering… the error was v is defined as the value so you have to do v.Parent in order to define and change other values/attributes of the parent.

   local Players = game:GetService("Players")
local PlacedItems = game.Workspace:WaitForChild("PlacedItems")

Players.PlayerRemoving:Connect(function(player)
	local Folder = PlacedItems:FindFirstChild(player.Name)
	Folder:Destroy()
	
	for _,v in pairs(game.Workspace.Paintable:GetDescendants()) do
		if v:IsA("StringValue") and v.Value == player.Name then
			v.Parent.ClickDetector:Destroy()
			v.Parent.Paintable.Value = true
			v.Parent.BrickColor = BrickColor.new("Dark stone grey")
		end
	end
	
end)

v:IsA("StringValue"), v.BrickColor.

String values don’t have a brick color.

1 Like