Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help in changing a specific area of smooth terrain material with a script?

(this is possible by the way)

-back story

ive been trying to make a script so when you click left mouse with the building script i've already made that sends a fire server, the part copies it's location and then changes that area to the specified terrain (dirt or cobblestone)

-been looking all over the place recently and im struggling on doing this script i tried with TerrainRegions and stuff like this

local dirtroad  = game.Workspace.dirtroad --TerrainRegion
-----
game.ReplicatedStorage.BuildingEvents.RoadEvents.dirtroadPlace.OnServerEvent:Connect(function(X,Y,Z)
local pos = Vector3int16.new (X,Y,Z)
print (X,Y,Z)
workspace.Terrain:PasteRegion(dirtroad, pos , true)
end)

but man am i struggling. if someone could point me in the right direction or even explain a lot i would really appreciate that! :)

here's some information of what i've been using

1 answer

#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 = {}; --// Allow us to store multiple CFrames.

local Click = 0
mouse.Button1Click:Connect(function() Click = (Click + 1)
   local Part = mouse.Target
   pcall(function()
      PartCFrames["ClickedPart"..Click] = Part.CFrame --// So each Element can be unique.
      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

0

Mega oof

0

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

0

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

0

Everything I gave above would still work for a regular hand-built terrain (Parts) keep in mind if you ever switch

This discussion is preserved as it was. New answers, comments, and votes are closed.