Part teleportation issue

  1. What do I want to achieve?
    I want to make a system where by having a part touch a another part (witch is the only part that can control other parts that touch it) and then teleport it to a area when teleported to that area it sets a bool value to true then other parts that are teleported go into another area (all the areas are invisible parts inside a model with bool values in them)
  2. What is the issue?
    It works for teleporting the first brick to an area but when it try’s teleporting more it try’s to go into the same area as the first part
  3. What solutions have I tried so far?
    I have searched around on the developer hub and YouTube and the forums and I cannot find a solution
local Cargo = game.Workspace.Positions:FindFirstChild("CargoPos")
local Position = Cargo.Position
Part=script.Parent

Part.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Union") and Cargo.HoldingCargo.Value == false then
		hit.Parent.Union.Position = Cargo.Position
		Cargo.HoldingCargo.Value = true
		print("Success")
	else
		print("Failed")
	end
end)

Could someone tell me how to get around this or another way to do this, Thanks!

Im a bit confused, are you trying to make a pad that teleports unanchored parts that are touching it to another area?

image

So you are trying to make a cargo system that when cargo is loaded onto the cargo train it will move the cargo from one spot to another?

no just when the cargo touches that highlighted part it will teleport to one of the half invisible boxs (the 3 next to eachother) then the next will teleport to a different one

Sorry, im just having difficulty understanding what is the main concept. Could you please explain the main concept of how its supossed to work?

Do you see where the 2 cargos are?

So your trying to make a conveyor belt that will move cargos into a teleport box that will teleport the cargo into a collection / storage area?

1 Like

yes Tthat is what im trying to do

Alright thanks! Let me just just the code.

alright thank you. 30char 30char

You could set that conveyor part’s velocity to something like this:

script.Parent.Velocity = script.Parent.CFrame.LookAt * 5 -- change 5 to whatever number you want.

(Might need to be within a while loop)

To teleport the parts, you could use PivotToor set their cframe.
Hope I understood you.

I know how to do all that its just when they teleport they try to all go to the same place and they dont go to another place if the other has a cargo already in it

Here is the improved code

local Positions = game.Workspace:WaitForChild("Positions") -- Get the positions definition

Hitbox = script.Parent -- Renamed Part to hitbox

function FindAvaliableCargoSpot() -- Uses a function instead of inbuilt
	local Test = false
	for i, v in pairs(Positions:GetChildren()) do -- Gets all cargo spots and returns one if there is an avaliable one
		if v.HoldingCargo.Value == false then -- Check if cargo spot is avaliable
			Test = true
			return v -- Return the cargo spot
		end
	end
	if Test == false then
		return nil -- Return nil as there is no avaliable cargo spots
	end
end

Hitbox.Touched:connect(function(hit)
	local CargoSpot = FindAvaliableCargoSpot()
	if hit.Parent:FindFirstChild("CargoPart") and CargoSpot ~= nil then -- Check if the part is a Cargo part and there is an avaliable spot
		hit.Parent.Union.Position = CargoSpot.Position -- Reposition it
		CargoSpot.HoldingCargo.Value = true -- Change the value
		print("Success")
	else
		print("Failed")
	end
end)

This code is better because it will automatically find the avaliable cargo spots, which means you can add as many cargo spots as you want and it will work. Also please rename the cargo “CargoPart” so the code can work properly.


I dont know if I named everything correct because it does not work

You dont have to rename anything else. You just have the rename the model that has the cargo parts “CargoPart”

Seems about right. Rename the folder that holds the cargo parts to something else then try it out!

17:34:40.170 Union is not a valid member of Model “Workspace.A”

I renamed the folder to a 30char