"Engine is not a valid member of NumberValue"

My script is
Engine = script.Parent.Engine
DieselEngine = script.Parent.DieselEngine
EngineSound = script.Parent.EngineSound

while true do
wait(5)
script.Parent.Value = 90
print(“Fuel 90”)
Engine:Play()
DieselEngine:Play()
EngineSound:Play()
wait(5)
script.Parent.Value = 80
print(“Fuel 80”)
wait(5)
script.Parent.Value = 70
print(“Fuel 70”)
wait(5)
script.Parent.Value = 60
print(“Fuel 60”)
wait(5)
script.Parent.Value = 50
print(“Fuel 50”)
wait(5)
script.Parent.Value = 40
print(“Fuel 40”)
wait(5)
script.Parent.Value = 30
print(“Fuel 30”)
wait(5)
script.Parent.Value = 20
print(“Fuel 20”)
wait(5)
script.Parent.Value = 10
print(“Fuel 10”)
wait(5)
script.Parent.Value = 0
print(“Fuel 0”)
Engine:Stop()
DieselEngine:Stop()
EngineSound:Stop()
wait()
end

and the output is
“Engine is not a valid member of NumberValue” Error

How should I fix this?!

1 Like

are you sure script.Parent.Engine exists?

Try

  local engine = script.Parent:WaitForChild("Engine")

Engine is a sound in it’s parent, yes.
image

Ohhh, I just figured it out. Yes it’s just me being stupid. I should’ve used script.Parent.Parent

1 Like

This isn’t your main issue, but you should consider using a tween or a numeric loop here. This is incredibly repetitive, but it could be simplified down to about 5 lines:

Engine:Play()
DieselEngine:Play()
EngineSound:Play()

for fuel = 90, 0, -10 do -- from 90 to 0, counting down by 10 (so it goes 90, 80, 70...), run the following code:
	script.Parent.Value = fuel -- set the value to the current number of the loop
	print("Fuel", fuel) -- print the current number in the loop
	wait(5) -- wait five seconds before moving onto the next iteration
end

You can find more information on loops on the wiki.

4 Likes