✓ Accepted answer
If the part you are wanting to modify is the one that the first script is creating, then you can change the values that are being set there.
In the first script, it creates a part and sets its Position, Size, and Name.
Make sure to set the variable part as a local variable.
Lets modify more properties.
local clickdetector = script.Parent:WaitForChild("ClickDetector")
clickdetector.MouseClick:Connect(function()
local part = Instance.new("Part")
local posz = math.random(-62,62)
local posx = math.random(-62,62)
part.Position = Vector3.new(posx,0,posz)
part.Size = Vector3.new(100,100,100)
part.Name = "COLORCHANGE"
part.BrickColor = BrickColor.random()
part.Material = "Neon"
part.Parent=game.Workspace
end)
In your second script, the part will change its color to a random one. Here it is changing the part's color property
Lets make it change its material to Plastic
There is also an error in your second script. You forgot to add an end to finish the if part then statement.
local clickdetector = script.Parent:WaitForChild("ClickDetector")
clickdetector.MouseClick:Connect(function()
local part = Workspace:FindFirstChild("COLORCHANGE")
if part then
part.BrickColor = BrickColor.Random()
part.Material="Plastic"
end
end)
A good practice is to not use the second parameter of Instance.new() More in depth reason
Sorry if your main question was to figure out why the script wasn't working. I thought you were asking how to change properties.
1 comment
Okay, Thank You!