You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear! Part changes to random color when clicked
What is the issue? Include screenshots / videos if possible! I am not writing the script correctly…
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
while game.Workspace.Part.ClickDetector.MouseClick.OnClick
do game.Workspace.Part.BrickColor = BrickColor.Random()
End (where did I go wrong pls help)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you! Part changes to random color each time is is clicked…
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Edit for clarity: MouseClick.OnClick isn’t a thing, and while whatever.ClickDetector.MouseClick do would just run for as long as the event exists, not when it fires, which would be always.
wait nvm my brain turned off, yeah it’s wrong.
Try what @HabibiBean did.
Or if you still prefer to use the while do method, it can work. It just needs a little fixing.
while workspace.Part.ClickDetector.MouseClick:Wait() do
workspace.Part.BrickColor = BrickColor.Random()
end
You should also either use it from a script inside of the click detector or make a variable to the specific part, otherwise you’ll have trouble actually finding it.
-- workspace.Part, wait what part? Just place the script inside the ClickDetector
-- solution is made by HabibiBean earlier
script.Parent.MouseClick:Connect(function()
script.Parent.Parent.BrickColor = BrickColor.Random()
end)
You should probably name the part you want the clicking to work on. Or place the script inside the part. It’s all up to you to decide.
I feel like going with an event is still the better choice, since this is a little too close for comfort to the while wait do idiom (and is also over-complicating things). This would work, yes, but it seems like a bad practice.
What I’d do here is call the MouseClick and at the same time get the Mouse.Target what object the mouse is clicking and basically just change the color. Here’s an example
Summary
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.ButtonClick:Connect(function()
local Target = Mouse.Target – If your part has no children
Target.BrickColor = BrickColor.new(“YourColorHere”)
game.ReplicatedStorage.ChangeAnyBrickColor:FireServer(Target:GetFullName)
end)
Server:
remote.OnServerEvent:Connect(function(Player, Path)
local Part = game[Path]
Part.BrickColor = BrickColor.new(“ColorHere”)
end)
Personally, I prefer to mimick the client’s behaviour of changing the color from both client and server, it may seem inconvenient here but I like to code securely.