"Attempt to call a nil value" Error

hello! i’ve been wanting to do a script where a tree is randomly put in a baseplate, but the script isn’t recognizing when i get the position.

screenshot

code:

placeTree()

function placeTree()
	local tree = assets.tree:Clone()

	tree:MoveTo(getPosition())
	tree.Parent = workspace
end

function getPosition()
	local x = Map.Position.X
	local xS = Map.Size.X / 2
	local y = Map.Position.Y + (Map.Size.Y / 2)
	local z = Map.Position.Z
	local zS = Map.Size.Z / 2
	--
	local pos = Vector3.new(math.random(math.min(x - xS), math.max(xS + x)), y, math.random(math.min(z - zS), math.max(zS + z)))

	return pos
end

You’re calling a nil value placeTree() before it’s even initialised. It’s like trying to start a car without having one yet. Everything has to be in order.

1 Like

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