What do you want to achieve?
I want my script to detect 2 bodymovers in the seat
What is the issue?
My script cannot find the certain object, i used FindFirstChild and it still cant find it
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
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
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!
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