In my Script, I keep getting the error “attempted to index nil with WaitForChild”, or " (xPart) is not a valid member of Model “UFO”. The script still runs as intended but this is really bugging me out, and I have no idea why its throwing errors.
local seat = script.Parent:WaitForChild("Seat")
local LV = script.Parent:WaitForChild("LinearVelocity")
while true do
if seat.Throttle == 1 then
if seat.Steer == 0 then
LV.VectorVelocity = seat.Occupant.Parent.HumanoidRootPart.CFrame.lookVector * 2
else
if seat.Steer == 1 then
-- FR
else
-- FL
end
end
elseif seat.Throttle == 0 then
if seat.Steer == 0 then
-- idle
else
if seat.Steer == 1 then
-- R
else
-- L
end
end
elseif seat.Throttle == -1 then
if seat.Steer == 0 then
-- B
else
if seat.Steer == 1 then
-- BR
else
-- BL
end
end
end
task.wait(0.1)
end
its a serverscript, and linearvelocity exists in the workspace as well as seat, neither are created by scripts. The UFO model is stored in ReplicatedStorage, until another script puts it into the workspace, however considering the script is inside the model I don’t see that that could be be causing the error
Unless LinearVelocity is created through a script or you’re requesting it from a localscript, there shouldn’t be any reason to be using :WaitForChild().
You should try using script.Parent.LinearVelocity, and if there’s an error then we can take a look at it and see what we can do.
I Changed it and its still getting the error, thanks for the info though, will do that from now on. But its the Seat that is causing the errors, not the linear velocity.
^ this one is from when it teleports you into the seat, it still teleports you into it but comes up with this error for some reason
^ and this is when defining seat in the script shown
(I changed seat to script.Parent.Seat as well, and still no change)
ok I have a theory, its when the UFO moves from Replicated Storage to workspace that it errors, so perhaps the roblox engine moves the model first and not the script, as its script.Parent that seems to be returning nil
It printed the table while it was in replicated storage, then when I transferred it into workspace by clicking E (which is how you “summon” the UFO), it threw this error
I’m unsure about how effective this is, but assuming your script is in ReplicatedStorage and it’s having difficulties with finding the Seat, we can try this approach.
When we clone the UFO into workspace, we will also clone the required script into the model.
We’ll make sure the script is disabled first, and enabled upon being cloned into the UFO model.
Ok that fixed the problem with that, the only remaining error is this one
After the UFO is parented to the workspace, and has undergone a cutscene of swooping down on the player, the line below teleports the player into the seat, and this is the line which is causing the only remaining error
tried all 3 of them, wait for child, normal dot, and first child. Me and glass have done some more looking though and it seems to be linked to inputbegan firing twice for some reason
Use SteerFloat instead of Steer and ThrottleFloat instead of Throttle, or at least this is what the documentation says, has you error fixed itself yet?