Can't get .Position from a returned part!

  1. I just want to get the .Position (the “Position” variable in the GetLocation function) parameter from the returned variable (a block part).

  2. I can get the part perfectly and their parameters, but can’t get its position (checked everything out using prints).

  3. I just looked for some solutions in different Discord servers and no one could helped me, but they told me to post my issue here.

local clone_Source = game.ServerStorage.AirCrate
local RNG = Random.new()
local crateWait = game.ServerStorage.GameConfigurations.AirCrateTook

local spawners_Folder = workspace.Map.AirCrateLocations
local num_of_spawners = #workspace.Map.AirCrateLocations:GetChildren()
local spawn_speed_min = 200
local spawn_speed_max = 300

function GetSpawner()
	local random_num = math.floor(math.random()*num_of_spawners)+1
	local spawner = spawners_Folder:FindFirstChild("AirCrate"..random_num)
	if not spawner then return end
	return spawner
end


function GetRandomLocationPlus100()
	local Part = GetSpawner()
	local Position = Part.Position
	local Size = Part.Size
	local MinX , MaxX= Position.X - Size.X/2, Position.X + Size.X/2
	local MinY, MaxY = Position.Y - Size.Y/2, Position.Y + Size.Y/2
	local MinZ, MaxZ = Position.Z - Size.Z/2, Position.Z + Size.Z/2
	local X, Y, Z = RNG:NextNumber(MinX, MaxX), RNG:NextNumber(MinY, MaxY), RNG:NextNumber(MinZ, MaxZ) 
	local RanPosition = Vector3.new(X, 100, Z)
	return RanPosition
end

Are you sure that the GetSpawner() function returns a BasePart, or is it a Model object? If it’s a model then you would need to use Model:GetPrimaryPartCFrame().Position. Don’t know if that’s relevant though.

It is a BasePart, I just printed it out (I even printed its .type and literally returned “Part”).

Are you sure that the GetSpawner function is actually returning a valid part?

local clone_Source = game.ServerStorage.AirCrate
local RNG = Random.new()
local crateWait = game.ServerStorage.GameConfigurations.AirCrateTook
local spawners_Folder = workspace.Map.AirCrateLocations
local num_of_spawners = #workspace.Map.AirCrateLocations:GetChildren()
local spawn_speed_min = 200
local spawn_speed_max = 300

function GetSpawner()
	local random_num = math.random(1, num_of_spawners)
	local spawner = spawners_Folder:WaitForChild("AirCrate"..random_num)
	if not spawner then return end
	return spawner
end

function GetRandomLocationPlus100()
	local Part = GetSpawner()
	local MinX, MaxX = Part.Position.X - Part.Size.X/2, Part.Position.X + Part.Size.X/2
	local MinY, MaxY = Part.Position.Y - Part.Size.Y/2, Part.Position.Y + Part.Size.Y/2
	local MinZ, MaxZ = Part.Position.Z - Part.Size.Z/2, Part.Position.Z + Part.Size.Z/2
	local X, Y, Z = RNG:NextNumber(MinX, MaxX), RNG:NextNumber(MinY, MaxY), RNG:NextNumber(MinZ, MaxZ) 
	local RanPosition = Vector3.new(X, 100, Z)
	return RanPosition
end

if not spawner then return end

Returns nil so make sure that isn’t occurring.

I did “print(Part)” in the GetRandomLocationPlus100 function and actually got a valid part.

I did “print(Part)” in the GetRandomLocation function and actually got a valid part.

Try the code I provided above.

Infinite yield possible on 'Workspace.Map.AirCrateLocations:WaitForChild(“AirCrate4”)