Detecting if part exists or not

local Part = script.Parent

local MoveAmount = 10

local function MakePath(StartPos,Orientation)

local Pos = (Part.CFrame * CFrame.new(Vector3.new(0,0,-MoveAmount/2))).Position

local Path = Instance.new("Part",game.Workspace.mazepath)

Path.Anchored = true

Path.Size = Vector3.new(6,1,MoveAmount+6)

Path.Position = Pos

Path.Orientation = Orientation

Path.Name = "Path"

end

local function Tween(Obj,Dura,Goal)

local TS = game:GetService("TweenService")

TS:Create(Obj,TweenInfo.new(Dura),Goal):Play()

wait(Dura)

end

local function MovePart(i)

local Pos = (Part.CFrame * CFrame.new(Vector3.new(0,0,-MoveAmount))).Position

Pos = Vector3.new(math.round(Pos.X),math.round(Pos.Y),math.round(Pos.Z))

local Rotation = math.random(0,4)

Part.Orientation = Vector3.new(0,Rotation*90,0)

local StartPos = Part.Position

local NPos = (Part.CFrame * CFrame.new(Vector3.new(0,0,-MoveAmount))).Position

local DetectCollisionRay = Ray.new(StartPos,NPos)

local Pt,Pn = game.Workspace:FindPartOnRay(DetectCollisionRay,Part,false,false)

if not Pt then

MakePath(StartPos,Part.Orientation)

elseif Pt.Name == "Border" then

return false

end

Part.Position = (Part.CFrame * CFrame.new(Vector3.new(0,0,-MoveAmount))).Position

end

wait(2)

while wait() do

local Var = MovePart()

if Var == false then

local Rotation = math.random(0,4)

Part.Orientation = Vector3.new(0,Rotation*90,0)

end

wait()

end

Code :arrow_double_up:

so i want my maze gen script to make it so that if a part exist then it wont place path if not it places path

Is this using a server script or a local script? I assume server

1 Like

yes its server (wow u guessed it correct)

1 Like

You can use FindFirstChild for that

Haha, sometimes new scripters don’t know the difference, I don’t know your skill level LOL.

Try using :FindFirstChild

what do you mean by that?

You see that “FindFirstChild” is blue right? Click on it and it will bring you to the api reference

i can see that but How is it suppose to help me? also there are MANY MANY parts not just one MANY

yea i am a veteran 1+ years of scripting and developing doe that wasnt a very good joke

Try working with something like this:

game.Workspace.mazepath:FindFirstChild('PART NAME HERE')

I personally learn by putting a basis of a script into the script and working with it until it works

the name is the same for all lol doe i could actually change the name :thinking:

Are they all in the same model?

no

Maybe create a table with the parts that it needs to make the path?

If that doesn’t work then you could model them all and use :GetDescendents then you can use if part isA(’’)

EDIT: I would try making a table and using waitforchild.

If you want to go simple then you could use a value that changes when the parts are no longer there
(I’m still trying to figure out what exactly you’re needing to do, so I’m listing things that I think could work for your purpose)

nvm i got it that how can i do it I did had a similar idea but then @michialok said FindFirstChild then you typed an example that made my brain have a pop cuz how stupid I could be LIKE I can just multiply its X Y Z with each other and that would create a UNIQUE NAME! thank you to both of you for helping

Haha, all good. Glad I could be of small assistance. Good luck.

thank you. you did helped a lot actually as you kinda reminded me how FFC works :sweat_smile: but as he gave idea so yea. Still thank you a lot and have a good day.