WorldRoot:GetPartsInPart not registering

  1. What do you want to achieve? Keep it simple and clear!

I am creating a bus that traverses the map, this bus is being tweened using a dummy part as a reference for the bus model.

While the bus traverses the map I would like to be able to register collisions but I have found it hard to accomplish this using .Touched or the method in the code below which is using WorldRoot:GetPartsInPart()

  1. What is the issue? Include screenshots / videos if possible!

I have not been able to consistently get parts that the bus collides with while traversing the map.

It initially registers a single iteration of the parts table when the bus spawns in, bus this includes irrelevant parts as the bus is not yet actually colliding with any relevant parts…

The while loop seems to only run once per bus.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried to use other methods like registering parts inside of the bus with .Touched but this similarly does not work for me.

	func = function(event)
		local angle = math.random() * 2 * math.pi
		local spawn = CFrame.new(workspace.Game.Islands.CentralIsland.PrimaryPart.Position - Vector3.new(0,20,0)) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, -250)
		local finish = CFrame.new(workspace.Game.Islands.CentralIsland.PrimaryPart.Position - Vector3.new(0,20,0)) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, 250)
		
		local bus = event_assets.Bus:Clone()
		local filter = {workspace.GameZone, bus.Base, bus.MeshPart1, bus.MeshPart2, bus.MeshPart3, bus.MeshPart4, bus.MeshPart5}
		bus:PivotTo(spawn)
		bus.Parent = workspace.Game.CleanUp
		
		local dummy = Instance.new("Part")
		dummy.Size = Vector3.new(1,1,1)
		dummy.CFrame = spawn
		dummy.CanCollide = false
		dummy.Anchored = true
		dummy.Transparency = 1
		dummy.CanTouch = false
		dummy.Parent = workspace.Game.CleanUp

		local Tween = TweenService:Create(
			dummy,
			TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false, 0),
			{CFrame = finish}
		)
		
		Debris:AddItem(bus, 5)

		Tween:Play()

		dummy.Changed:Connect(function(property)
			if property == "CFrame" then
				bus:PivotTo(dummy.CFrame)
			end
		end)
		
		while bus do
			local parts = workspace:GetPartsInPart(bus.Hitbox)
			print(parts)
			print(1)
			
			for _, part in parts do
				local character = part:FindFirstAncestorOfClass("Model")
				local humanoid = character:FindFirstChildOfClass("Humanoid")
				print(2, part.CollisionGroup)
				if humanoid or part.CollisionGroup == "destructible" then
					print(3)
					if humanoid then
						print(3.1)
						humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
						part = character:FindFirstChild("HumanoidRootPart")
					elseif part.CollisionGroup == "destructible" then
						part.Anchored = false
						print(3.2)
					end
					
					print("applying impulse")
					part:ApplyImpulse(bus.PrimaryPart.CFrame.LookVector * 1000)
				end
			end
			
			rs.Stepped:Wait()
		end
	end,

Thank you

local character = part:FindFirstAncestorOfClass("Model")
local humanoid = character:FindFirstChildOfClass("Humanoid") 

I had to make sure that character was not nil

Seems like you’ve figured it out yourself right?

Indeed if character were to be nil the loop will error

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