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

[SOLVED] Why does my game/studio crash when attempting to run this script?

I think the issue is terrain:ReplaceMaterial

I have rewritten it several times, but running the script will always end up crashing the game. I am attempting to get a region of terrain replaced with a different material when clicking the button

local open = true

--GFX VARIABLES--
local Bloom = game.Lighting.Bloom
local Blur = game.Lighting.Blur
local SunRays = game.Lighting.SunRays
local Shadows = game.Lighting.GlobalShadows
--GFX VARIABLES--


--GRASS POSITION SETTINGS--
local min = game.Workspace.Part1
local max = game.Workspace.Part2

local Region = Region3.new(min.Position, max.Position)
local materialToReplace = Enum.Material.Grass
local replacementMaterial = Enum.Material.LeafyGrass
--GRASS POSITION SETTINGS--


script.Parent.MouseButton1Click:Connect(function()
	if open == true then
		Bloom.Enabled = false
		Blur.Enabled = false
		SunRays.Enabled = false
		Shadows = false
		Region = Region:ExpandToGrid(4)
		workspace.Terrain:ReplaceMaterial(Region, 4, materialToReplace, replacementMaterial)
		open = false
		script.Parent.Text = "Fast GFX [Active]"
	else
		Bloom.Enabled = true
		Blur.Enabled = true
		SunRays.Enabled = true
		Shadows = true
		Region = Region:ExpandToGrid(4)
		workspace.Terrain:ReplaceMaterial(Region, 4, materialToReplace, replacementMaterial)
		open = true
		script.Parent.Text = "Fast GFX [InActive]"
	end
end)	

1 answer

i figured it out i guess for some reason having the region already divisible by 4 crashes the game if you try to use Region:ExpandToGrid(4)

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