Error with brick colour change gui

trying to make a gui that changes the colour of the players car and cant get it to work.

Getting this error


image

Script V

script.Parent.MouseButton1Click:Connect(function() --Change Part with your Brick name

script.Parent.Parent.Parent.Parent.Body.Paint.PAINT.BrickColor = BrickColor.new("Really blue")

end)

This is how the car is organized

image
image

unsure why or what to do ;/

1 Like

You shouldn’t be doing

script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent

And having a million .Parents to get the player. Just do

game.Players.LocalPlayer

The statement you’re using is leading to the player, not the vehicle.

I realized, I have a car spawner and when it spawns the car it gets the players name then adds the car to the worspace
image

example above

basically if some spawns it would be whatever their name is car so i guess i would have to do something like this

	script.Parent.MouseButton1Click:Connect(function() --Change Part with your Brick name
	game.Workspace.playercar.Body.Paint.PAINT.BrickColor = BrickColor.new("Black")
end)

i used player car as an example.

but im wondering how would i make sure it tells the players name then car. like if idk roblox joined it would say RobloxCar but i would have to make sure the script knows that after workspace.

1 Like

Make another variable like this:

local playersvehicle = nil

Then when the player gets the car, change that value to the name of the vehicle. Then you can use it to search for it in workspace like this:

workspace[playersvehicle].Body

Is this what you mean?

local playersvehicle = nil

script.Parent.MouseButton1Click:Connect(function() --Change Part with your Brick name

game.Workspace[playersvehicle].Body.Paint.PAINT.BrickColor = BrickColor.new("Black")

end)

sorry im not really to sure. but im now getting this error

This is a good example of why you should not just copy the code. You need to replace nil with the vehicle

Inside the square brackets should be the name of the vehicle (so if the variable playersvehicle is a string (“Hi”) then it will look for something named “Hi” in Workspace as well) But substituting the string with nil gives the error shown above

1 Like

yea, but would this even work for something like this?

cause here is what i’m talking about how it names the car for that player

Just use any string as the variable, and it will look for a child in the workspace with the same name as the string. For example, if playersvehicle = “Example”, and there was a part named Example in workspace, then game.Workspace[playersvehicle] would get Example.

1 Like

Scratch that, let me explain.

When adding

local namedplayer = nil

You’re letting this variable be blank, you can then write to this variable later on. In a local script, you should have this:

local namedplayer = nil

namedplayer = game:GetService("Players").LocalPlayer.Name

This will then apply the users name to ‘namedplayer’.

You can use this to fire a remoteevent to the server, which will fire the ‘namedplayer’ variable over to the server for further use. Then you can assign the Vehicles name using that variable with an ‘OnServerEvent’.

Does this make more sense?

1 Like

Kind of, But I’m confused why something like what I did before didn’t work as planned. I’ll try my best to figure this out though. Thanks for helping guys.

It’s happening because you’re trying to find ‘body’ inside the player

1 Like

oh. well then how would i make it for the car? and make it paint only the parts name PAINT in the paint model?

I’m finding this very hard to explain over text, do you have discord?