Need help with Painting GUI

  1. What do you want to achieve?
    I’m trying to create a painting GUI for the player to paint their house however they’d like.

  2. What is the issue?
    My script within the GUI TextButton isn’t working :confused:
    I’m trying to make it so that when the button is clicked, the part that the player is painting changes to the selected color on their plot & nobody else’s plot.

  3. What solutions have you tried so far?
    I’ve tried searching Youtube videos and the DevForum but I couldn’t find videos/posts specific to the issue I’m having. The Youtube videos weren’t very detailed and went over how to color a part but nothing else.

Right now I’m attempting to create the script for the fence paint—here’s the script & explorer layout below!

Fence Button LocalScript:

local plr = game.Players.LocalPlayer
local PlotClaimed = plr.PlotClaimed
local painting = false

script.Parent.MouseButton1Click:Connect(function()
	if PlotClaimed.Value == false then return end
	
	if painting == false then
		painting = true
		script.Parent.Parent.Parent.Frame.Visible = false
		script.Parent.Color.Visible = true
	end
end)

Screen Shot 2022-07-26 at 12.42.46 PM

Color Button LocalScript:

local plr = game.Players.LocalPlayer
local PlotClaimed = plr.PlotClaimed
local painting = false

script.Parent.MouseButton1Click:Connect(function()
	
	for i ,v in pairs(game.Workspace.PlotFolder:GetDescendants()) do
		if v.Name == "PlayerName" and v:IsA("StringValue") then
			if v.Value == tostring(plr.Name) then
				painting = true
				
				for i ,v in pairs(game.Workspace.PlotFolder:GetDescendants()) do
					if v.Name == "Fences" then
						local Fences = (v.Parent:FindFirstChild("Fences") 
							Fences.Color = Color3.fromRGB(218, 253, 255) 
							
					end
				end
			end
		end
	end
	end)

Screen Shot 2022-07-26 at 12.43.27 PM

PlotFolder Layout & House:


ClaimPart Script:
Screen Shot 2022-07-26 at 12.52.07 PM

	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr and script.Parent.Parent.PlotClaim.Value == false then
			local PlotClaimed = plr.PlotClaimed
			PlotClaimed.Value = true
			script.Parent.Parent.PlayerName.Value = tostring(plr.Name)
			script.Parent.Parent.PlayerNamePart.SurfaceGui.PlayerNameLabel.Text = tostring(plr.Name) .. "'s House"
		end
	end
end)

This is supposed to go along with a placement system I’ve created hence the “DetectPart” is the area in which the player can place the item.

Let me know if you need any more information! :slight_smile:

1 Like

I’m not sure what I’m doing incorrectly— the “Fences” in

Fences.Color = Color3.fromRGB(218, 253, 255)

is underlined in red & I’m not sure how I’d have the script target the player’s plot specifically?

This is because Fences is a model and not a basepart.
You could try something like this:

local Fences = (Where fences is located)

for i, v in pairs(Fences:GetDescendants()) do
	if v:IsA("BasePart") then
		v.Color = Color3.fromRGB(218, 253, 255)
	end
end

This finds all the children of the model “Fences” and changes their color if it’s a basepart.

Would this only paint the fences on the player’s plot? Or would it paint all fences in all of the plots within the PlotFolder?

Depends on what you set the Fences variable to. If you set it to the PlotFolder then it will get all the stuff inside that folder/model. If you set it to the fences on the player’s plot it will get all the stuff inside that folder/model.

EDIT:
It searches for everything in the given instance, meaning it will check the decedents of the decedents as well.

I see! Well if all the plot’s are named “Plot” and if I were to define the variable to

local Fences = game.Workspace.PlotFolder.Plot.House:FindFirstChild(Fences)

then would it paint all the fences? I’m trying to have it solely paint the player’s fences within their plot.

This is the script I’ve written but it’s not working:

local plr = game.Players.LocalPlayer
local PlotClaimed = plr.PlotClaimed
local painting = false

script.Parent.MouseButton1Click:Connect(function()

	for i ,v in pairs(game.Workspace.PlotFolder:GetDescendants()) do
		if v.Name == "PlayerName" and v:IsA("StringValue") then
			if v.Value == tostring(plr.Name) then
				painting = true

				for i ,v in pairs(game.Workspace.PlotFolder:GetDescendants()) do
					if v.Name == "Fences" then
						local Fences = (v.Parent:FindFirstChild("Fences"))
							Fences = Color3.fromRGB(218, 253, 255) 

					end
				end
			end
		end
	end
end)

EDIT: I guess what I’m trying to do more specifically is when the player clicks the button, it searches for whichever plot the player has claimed, then searches for the “Fences” model within the “House” folder, and then changes the color to the desired color.