I have no idea why this part isn't changing color

Yes, they all print
img-2023-12-02-21-34-01

I understand there’s no erroring, but have you manually checked to see that the color of the part is changing?

If you mean the colors in the selection gui then yes, I checked every color and none of them work.

I mean the color of the car itself. Is the color of the car changing when you tell it to?

Nope, it doesnt change in the script

I assume then the gui variable is something like:
local gui = script.parent

and hopefully the bodyColorFrame variable comes from that gui variable.

Since we don’t see the definition of those variables in the script I also assume that the code you sent isn’t the whole script.

If it changes when manually changing the color in studio, but it doesn’t within the script, and it also doesn’t error, my first instincts tell me that its latching onto a preview car, but not the one the player actually is looking at. Otherwise, without having more context, I’m stumped.

I would agree here. Until we have the rest of the code I don’t think we can figure out the issue here, because the code we’ve been presented with looks fine minus a few critiques that don’t really matter here atm and not like it’d cause a problem.

1 Like

Here’s the full code sorry for not giving it earlier

local gui = script.Parent

local clicksound = gui.Click_Sound
local hoversound = gui.Hover_Sound

local toggle = gui["Open/Close"]
local togglebutton = toggle.Button
local toggletext = toggle.Text

local custom = gui.Customize
local customFrame = custom.CustomFrame
local selectionFrame = custom.Selection

local bodyColorFrame = customFrame.BodyColor
local windowColorFrame = customFrame.WindowColor

local state = false
local toggledebounce = false

local carobjvalue = gui.PreviewCar

togglebutton.MouseButton1Click:Connect(function()
	if toggledebounce == false then
		toggledebounce = true
		hoversound:Play()
		for i, v in pairs(customFrame:GetChildren()) do
			v.Visible = false
		end
		if state == false then
			state = true
			local tweenInfo = TweenInfo.new(0.3 , Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
			local Goal = {
				Rotation = 180
			}
			local Close = game:GetService("TweenService"):Create(toggletext, tweenInfo, Goal);
			Close:Play()
			
			local tweenInfo = TweenInfo.new(0.3 , Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
			local Goal = {
				Position = UDim2.new(0.5,0,0.1,10)
			}
			local OpenGui = game:GetService("TweenService"):Create(custom, tweenInfo, Goal);
			OpenGui:Play()
			
			wait(0.3)
		else
			state = false
			local tweenInfo = TweenInfo.new(0.3 , Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
			local Goal = {
				Rotation = 0
			}
			local Open = game:GetService("TweenService"):Create(toggletext, tweenInfo, Goal);
			Open:Play()
			
			local tweenInfo = TweenInfo.new(0.3 , Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0)
			local Goal = {
				Position = UDim2.new(0.5,0,-1,10)
			}
			local CloseGui = game:GetService("TweenService"):Create(custom, tweenInfo, Goal);
			CloseGui:Play()
			
			wait(0.3)
		end
		toggledebounce = false
	end
end)

for i, v in pairs(selectionFrame:GetChildren()) do
	if v:IsA("Frame") then
		v.Button.MouseButton1Click:Connect(function()
			hoversound:Play()
			local name = v.Name
			for i, v in pairs(customFrame:GetChildren()) do
				v.Visible = false
			end
			if customFrame:FindFirstChild(name) then
				customFrame:FindFirstChild(name).Visible = true
			end
		end)
	end
end

for _, part in pairs(bodyColorFrame:GetChildren()) do
	if part:IsA("Frame") then
		local button = part.Button
		local values = part.Values
		
		button.MouseButton1Click:Connect(function()
			hoversound:Play()
			print("clicked")
			if carobjvalue.Value ~= nil then
				print("not nil")
				local carprev = carobjvalue.Value
				print(carprev)
				for _, obj in pairs(carprev:GetDescendants()) do
					print("checking")
					if obj.Name == "Customize" and obj:IsA("StringValue") then
						print("found value")
						if obj.Value == "BodyColor" then
							print("found right value")
							print(obj.Parent)
							--local r, g, b = values.Color.Value.R*255, values.Color.Value.G*255, values.Color.Value.B*255
							--local RGB_Color = Color3.new(r,g,b)
							--print(RGB_Color)
							obj.Parent.Color = values.Color.Value 
							print(obj.Parent.Color)
							print(values.Color.Value)
							carprev.BodyColor.Value = values.Color.Value
						end
					end
				end
			end
		end)
	end
end

Could you send an image of the hierarchy in workspace for the UI in question? I feel that’ll help with diagnosing the issue here.

This might be the issue. You have the car I assume set in this object value. If its set to the one that’s in your StarterGui, then you are changing the color of the car that’s located in the StarterGui folder rather than the gui that’s cloned to the player when they spawn.

If there is a way to get the carobjvalue stemming from this script, such as

local carprev = script.Parent.Parent.CarObj -- this is just an example

This way it will locate the car that’s in the PlayerGui folder rather than the one in StarterGui.

I finally found out the problem. Whenever you enter the garage I made a script where the car gets cloned from replicated storage into the workspace. The object value was referencing the sample inside replicated storage instead of the actual model.

image

The problem was actually in a different script and not the one I thought it was.

2 Lines of code were causing this issue:

local car = game.ReplicatedStorage.Objects.CarDisplay:FindFirstChild(carname)
car:Clone().Parent = garage.Vehicle

I fixed it by moving the :Clone() to the first line of code so it would be like game.ReplicatedStorage.Objects.CarDisplay:FindFirstChild(carname):Clone()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.