Why doesn't my script control where the rigs primary part goes to

local AttitudeHandler = require(script.AttitudeHandler)
local Needs = require(script.CustomerNeedsHandler)
local PathFindingService = game:GetService("PathfindingService")

local INCREMENT = 0
local MAX = 10

local CUSTOMERDELAY = 1

local CustomerHolder = {}

local CustomerHandler = {}
CustomerHandler.__index = CustomerHandler




function CustomerHandler.new(model,StartPosition:CFrame)
	local rotation = CFrame.Angles(0, math.rad(360), 0) 
	local self = setmetatable({}, CustomerHandler)

	self.RIG = model:Clone()
	self.RIG.Parent = workspace
	self.RIG:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
	INCREMENT = INCREMENT + 1
	self.RIG.Name = "Customer".. INCREMENT
	
	table.insert(CustomerHolder,self.RIG.Name)
	

	self.RIG:PivotTo(model:GetPivot() * rotation)
	self.Atitude = AttitudeHandler.Generate()
	self.Need = Needs.Generate()
	self.RIG:SetAttribute("Atitude",self.Atitude:GetAttitude())
	self.SetNeed = self.RIG:SetAttribute("Wants",self.Need:GetNeed())
	
	return self
end

function CustomerHandler:PathFind(EndPoint)
	if INCREMENT > MAX then
		table.clear(CustomerHolder)
		self.RIG:Destroy()
		return
	end
	
	
	local path = PathFindingService:CreatePath({
		AgentRadius = 2,
		AgentHeight = 5,
		AgentCanJump = false
	})

		local success, errorMessage = pcall(function()
		path:ComputeAsync(self.RIG:WaitForChild("HumanoidRootPart").Position, EndPoint)
		end)
		
		
		if success and path.Status == Enum.PathStatus.Success then
			-- For each waypoint, create a part to visualize the path
			for _, waypoint in path:GetWaypoints() do
				local part = Instance.new("Part")
				part.Position = waypoint.Position
				part.Size = Vector3.new(0.5, 0.5, 0.5)
				part.Color = Color3.new(1, 0, 1)
				part.Anchored = true
				part.CanCollide = false
				part.Parent = game.Workspace
				self.RIG:FindFirstChild("Humanoid"):MoveTo(part.Position)
				part:Destroy()
			end
			
			
		self.RIG:FindFirstChild("Humanoid").MoveToFinished:Connect(function()
				task.wait(CUSTOMERDELAY)
				local Model = game.ReplicatedStorage.Customers.Customer
			local NewCustomer = CustomerHandler.new(Model)
			print("Sup")
				local NextCustomerHB = Instance.new("Part",workspace)
				--HitBox Stats
				NextCustomerHB.CFrame = self.RIG:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0,0,3)
				NextCustomerHB.Name = "Fornite"
				NextCustomerHB.Anchored = true
				NextCustomerHB.Size = Vector3.new(7.24, 7.12, 4.33)
				NextCustomerHB.BrickColor = BrickColor.new("Crimson")
				NextCustomerHB.CanCollide = false
				NextCustomerHB.Transparency = 1
				
				NewCustomer:PathFind(NextCustomerHB.Position)
		end)
		
	end
end






return CustomerHandler

Line 24 is what changes the primary part cframe but for some reason it doesnt change. (And I didn’t forget to require my module)

You don’t seem to be using StartPosition anywhere.
Also try combining your SetPrimaryPartCFrame and PivotTo calls into a single PivotTo call.

1 Like

so wait like this

SetPrimaryPartCFrame(PivotTo())

No, use just :PivotTo() (SetPrimaryPartCFrame is deprecated and shouldn’t be used in new work)

It might be just the way I coded it but I cant change the position of the rig anywhere even if I use pivoTo() its stays in the same place that it was at when I put it in replicated storage

Move the HumanoidRootPart itself

You forgot to implement StartPosition

I just implemented the startposion and thats not the reason why it didnt work its still stays in this one position

Can you show how you implemented it?

self.RIG = model:Clone()
	self.RIG.Parent = workspace
	self.RIG:PivotTo(StartPosition)
	INCREMENT = INCREMENT + 1
	self.RIG.Name = "Customer".. INCREMENT

Print StartPosition to check if your scripts are calling the function with an incorrect CFrame

I dont see any problem with the startposition cframe

You don’t pass a CFrame to the CustomerHandler.new call at line 77, check if that’s your issue.

Thanks alot what you said was not what fixed it but it gave me and idea on how to fix and it works thanks alot

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