I am trying to make it so when a player clicks and if their mouse is on terrain it replaces it with ice
local movepart = game.Workspace:WaitForChild("HoverPart")
local mouse = game.Players.LocalPlayer:GetMouse()
local mousex = mouse.Hit.Position.X
local mousey = mouse.Hit.Position.Y
local mousez = mouse.Hit.Position.Z
local reigon = Region3.new(Vector3.new(mouse.Hit.Position.X,mousey,mousez), Vector3.new(mouse.Hit.Position.X,mousey,mousez))
function Mousedown()
workspace.Terrain:ReplaceMaterial(reigon, 4, Enum.Material.Ground, Enum.Material.Ice)
end
mouse.Button1Down:Connect(function()
workspace.Terrain:ReplaceMaterial(reigon, 4, Enum.Material.Ground, Enum.Material.Ice)
end)
I already have the part that goes to the mouse btw
For starters, you need to update the region for the most recent mouse click. Currently your code only stores a region for the mouse’s initial hit (which is probably nil).
I believe you also probably want to call ExpandToGrid(4) on the region to make it match the terrain’s grid.
local resolution = 4
mouse.Button1Down:Connect(function()
if not mouse.Hit then
return
end
local reigon = Region3.new(Vector3.new(mouse.Hit.Position.X,mousey,mousez), Vector3.new(mouse.Hit.Position.X,mousey,mousez)):ExpandToGrid(resolution)
workspace.Terrain:ReplaceMaterial(reigon, 4, Enum.Material.Ground, Enum.Material.Ice)
end)