Having trouble with models not been in line with waypoints

I’ve been working on a game alongside a friend and i’m trying to spawn objectives in form of models around the map.
It works but the way they spawn frustate me.

If you see the picture below I made waypoints with a arrow indicating where the objective should point towards, most of the time it works fine but other times it just don’t.


image
image

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local wayPoints = workspace.CurrentMap:WaitForChild("Waypoints")
local objectiveProp = ReplicatedStorage:WaitForChild("ObjectiveProps")

local selectedGens = 0
local selectedGastanks = 0
local selectedFusebox = 0

function spawnObjective()
	local getGenPoints = wayPoints.Generator:GetChildren()
	print(getGenPoints)
	
	local getGastankPoints = wayPoints.Gastank:GetChildren()
	print(getGastankPoints)
	
	local getFuseboxPoints = wayPoints.Fusebox:GetChildren()
	print(getFuseboxPoints)
	
	repeat
		local selectedGenPoint = getGenPoints[math.random(1, #getGenPoints)]
		print(selectedGenPoint)
		
		if selectedGenPoint.IsWaypointTaken.Value == false then
			local genModel = objectiveProp:WaitForChild("GeneratorModel")
			local newGen = genModel:Clone()
			newGen.Parent = workspace
			newGen:MoveTo(selectedGenPoint.Position + Vector3.new(0, newGen.PrimaryPart.Size.Y/2, 0))
			newGen:PivotTo(newGen:GetPivot() * CFrame.Angles(0, math.rad(selectedGenPoint.Rotation.Y), 0))
			selectedGens += 1
			
			selectedGenPoint.IsWaypointTaken.Value = true
		end
		task.wait(0.1)
	until selectedGens == 4
	print("All generators are spawned")
	
	repeat
		local selectedGastankPoint = getGastankPoints[math.random(1, #getGastankPoints)]
		print(selectedGastankPoint)

		if selectedGastankPoint.IsWaypointTaken.Value == false then
			local gastankModel = objectiveProp:WaitForChild("GastankModel")
			local newGastank = gastankModel:Clone()
			newGastank.Parent = workspace
			newGastank:MoveTo(selectedGastankPoint.Position + Vector3.new(0, newGastank.PrimaryPart.Size.Y/2, 0))
			newGastank:PivotTo(newGastank:GetPivot() * CFrame.Angles(0, math.rad(selectedGastankPoint.Rotation.Y), 0))
			selectedGastanks += 1

			selectedGastankPoint.IsWaypointTaken.Value = true
		end
		task.wait(0.1)
	until selectedGastanks == 5
	print("All gas tanks are spawned")
	
	repeat
		local selectedFuseboxPoint = getFuseboxPoints[math.random(1, #getFuseboxPoints)]
		print(selectedFuseboxPoint)

		if selectedFuseboxPoint.IsWaypointTaken.Value == false then
			local fuseboxModel = objectiveProp:WaitForChild("FuseboxModel")
			local newFusebox = fuseboxModel:Clone()
			newFusebox.Parent = workspace
			newFusebox:MoveTo(selectedFuseboxPoint.Position + Vector3.new(0, newFusebox.PrimaryPart.Size.Y/2, 0))
			newFusebox:PivotTo(newFusebox:GetPivot() * CFrame.Angles(0, math.rad(selectedFuseboxPoint.Rotation.Y), 0))
			selectedFusebox += 1

			selectedFuseboxPoint.IsWaypointTaken.Value = true
		end
		task.wait(0.1)
	until selectedFusebox == 5
	print("All fuseboxes are spawned")
	
end

spawnObjective()

Can you screenshot the explorer with all of the relevant models? I can probably help you a little more if I have that.

1 Like