#Breaking it down together
This would be quite an easy, though complicated task when you truly think. This is an interesting project and I’d be glad to help!
Firstly, it’s easiest to break down the task in pieces, so it seems easier, and is more organized.
So for the first part, we need to know when the Player LeftClicks. You can check for this numerous ways, but the fastest way we can use is Button1Down of mouse.
This is a Signal, so we have to treat it like one, meaning we use the format below to attach a Listener that will run the desired Code on-Click.
local Player = game: GetService("Players").LocalPlayer
local mouse = Player:GetMouse()
mouse.Button1Click:Connect(function()
end)
Great! First part finished. Second, we have to get the Object the mouse is currently hovering over. This can be achieved with Target, of mouse.
Since we’ll be referencing the Target a few times, we’ll store it in a variable.
local Player = game: GetService("Players").LocalPlayer
local mouse = Player:GetMouse()
mouse.Button1Click:Connect(function()
local Part = mouse.Target
end)
Finally, we want to store it’s current CFrame and change it’s Material, these are properties we can store, and apply with variables, so we will do so.
Though before actually go through with this, we should use a pcall. Why you may ask? Well, Target is whatever mouse is overtop of, Target will only return BaseParts so if we look at the Sky and Click, Target will be nil. We wan’t to make sure we don’t error the Script, so it’s best to do this.
local Player = game: GetService("Players").LocalPlayer
local mouse = Player:GetMouse()
local PartMaterial = Enum.Material.Cobblestone
local PartCFrames = {};
local Click = 0
mouse.Button1Click:Connect(function() Click = (Click + 1)
local Part = mouse.Target
pcall(function()
PartCFrames["ClickedPart"..Click] = Part.CFrame
Part.Material = PartMaterial
end)
end)
We’re all done!
Hope this helps! If there’s anything you need clarification on, or like me to further interpret, please comment! If this helps, don’t forget to accept this answer! and optionally upvote:)
4 comments
Mega oof
thanks for trying to help :) but i dont think i was being very specific, i already had done the click part with my building system ive made, and im trying to do smooth terrain material and not a part material
I realized:) I don’t think you can change the smooth terrain material, it is originally plastic and doesn’t look plastic at all. E.g I don’t think it effects it
Everything I gave above would still work for a regular hand-built terrain (Parts) keep in mind if you ever switch