Advertisement
SkidScripts

change color of a part roblox studio (lua)

Nov 29th, 2023
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. ------------------------------------------------------------------------------
  2.  
  3.  
  4. -- Get the part you want to interact with (replace "Part" with the name of your part in Roblox)
  5. local part = script.Parent
  6.  
  7. -- Function to change color
  8. local function changeColor()
  9.     -- Generate a random color
  10.     local randomColor = Color3.new(math.random(), math.random(), math.random())
  11.    
  12.     -- Change the color of the part
  13.     part.BrickColor = BrickColor.new(randomColor)
  14. end
  15.  
  16. -- Connect the function to the part's ClickDetector
  17. part.ClickDetector.MouseClick:Connect(changeColor)
  18.  
  19.  
  20. ----------------------------------------------------------------------------
  21.  
  22. To use this code:
  23.  
  24. Open Roblox Studio and create a new script.
  25. Copy and paste the above Lua code into the script.
  26. Attach the script to the part you want to interact with by placing the script under the part in the Explorer or by dragging it onto the part in the 3D view.
  27. When you run your game in Roblox Studio and click on the part in the game, it should change color each time it's clicked due to the attached script.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement