Roblox being suck at math

i was making generation terrain with cubes like, when cube is too high, it should be mountain but if cube is too low, it should be grass but Math is not working :confused:

Ignore others scripts,

local cube = script.Parent
local x = 0
local y = -1
for i = 1,100 do
	local terrain = cube:Clone()
	task.wait()
	x += 1
	if math.random(1,2) == 1 then
	 y += math.random(-1,1)
	end
-- Target -- 
	if terrain.Position.Z <= 15 then
		print("grey")
		print(y)
		terrain.Material = Enum.Material.Slate
		terrain.BrickColor = BrickColor.new("Grey")
	else
		terrain.Material = Enum.Material.Grass
		print(y)
		print("grass")
		terrain.BrickColor = BrickColor.new("Dark green")
	end
-- Target -- 
	terrain.Position = Vector3.new(-x,y,terrain.Position.Z)
	terrain.Script:Destroy()
	terrain.Parent = workspace
end

How i do fix it??
when i tried Simple if then. the result is right answer but this script? no

lua
	if terrain.Position.Z <= 15 then
		print("grey")
		print(y)
		terrain.Material = Enum.Material.Slate
		terrain.BrickColor = BrickColor.new("Grey")
	else
		terrain.Material = Enum.Material.Grass
		print(y)
		print("grass")
		terrain.BrickColor = BrickColor.new("Dark green")
	end

Which axis did you mean to check? Y or Z?


This is saying anything with a Z axis greater than 15 should be grass.

wait nvm i fixed it. I changed Z to Actual Variable, i am so dumb

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.