My FindFirstChild script can't find the object

  1. What do you want to achieve?
    I want my script to detect 2 bodymovers in the seat

  2. What is the issue?
    My script cannot find the certain object, i used FindFirstChild and it still cant find it

  3. What solutions have you tried so far?
    Well i was studying more about FindFirstChild, seems like i did nothing wrong in my script!

My script:

local Seat =  script.Parent

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		wait(1)
		local Gyro = script.Parent:FindFirstChild("Gyro")
		local Move = script.Parent:FindFirstChild("Move")
		if Gyro then
			print("gyro detected")
			Gyro:Destroy()
			print("gyro removed")
			wait()
			if Move then
				print("Move detected")
				Move:Destroy()
				print("move removed")
			end
		end
	end
end)

the 2 objects that my script is supposed to detect "Gyro and Move: here

Ah, You can use

WaitForChild:("Gyro",TimeOut)

Or

for i,v in pairs(script.Parent:GetChildren()) do
   if v:IsA("BodyGyro") then -- ClassName of the part
      -- Your Code Here
   end
end

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

I noticed the issue, turns out my script doesnt detect things thats added after my script runs, but i added “wait(1)” function so it can detect the object a second after the script runs but it still doesnt work, i cant find any threads about this issue

I dont think about this, maybe… maybe roblox have some kind of anti cheat like that, auto detect body gyro and destroy/remove it ?

local Seat =  script.Parent

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		wait(1)
		local Gyro = script.Parent:WaitForChild("Gyro")
		local Move = script.Parent:WaitForChild("Move")
		if Gyro then
			print("gyro detected")
			Gyro:Destroy()
			print("gyro removed")
			wait()
			if Move then
				print("Move detected")
				Move:Destroy()
				print("move removed")
			end
		end
	end
end)

WaitForChild yields the code until the given object is found!

If it throws you an Infinite Yield, it’s because your body gyro literally doesn’t exist, which gives you the answer to your question!

I even tried that, it keeps sending infinite yields, here is the picture that explains it all here

Are you trying to change sound pitch when vehicle moves?

whatever script it is, I’m just trying to make it detect the “Move” BodyVelocity but the script says it doesnt exist

Is the script in the same model as the Move?

Maybe you should make sure the Gyro and Move don’t change their parents when the game runs. So just run the game and try to find if the Seat has any children named Gyro and Move.

Yes it is, but there is a script that adds these body velocities when i sit in the seat, so these scripts that are attempting to detect the body velocities run before the body velocities exist

Then combine the scripts and run the add first, then the detect.

Also, you can have the gyro and such already in the seat, with no values… then adjust the values when the player sits in the seat via script.