Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this Script Work in Test Mode Only?

I know it's a free model, but I've always wondered WHY it stopped working. I know some ROBLOX update broke it around a year ago. It caused most vehicle tool scripts to break and not do anything when commanded. Can anyone look at it and see what's wrong with it please? It works fine in Test mode, just not in online

Here's the script:

fly = false
turn = false
fire = true
a = 25
hover = false

function onFire(gun)
	local b = Instance.new("Part")
	b.Parent = game.Workspace
	b.CFrame = gun.CFrame + (gun.CFrame.lookVector * 10)
	b.formFactor = 2
	b.Size = Vector3.new(1,1,2)
	b.TopSurface = 0
	b.BottomSurface = 0
	b.BrickColor = BrickColor.new(24)
	b.Reflectance = 0
	b.Name = "Rocket"
	local bv = Instance.new("BodyVelocity")
	bv.velocity = gun.CFrame.lookVector * 400
	bv.Parent = b
	local s = script.Parent.Rocket:Clone()
	s.Disabled = false
	s.Parent = b
end

function onButton1Down(mouse)
	if fly == true then
		turn = true
		while turn == true do
			if heli ~= nil then
				if heli.Parts:FindFirstChild("Engine") ~= nil then
					heli.Parts.Engine.BodyGyro.cframe = mouse.Hit
				end
			end
			wait(0.1)
		end
	end
end

function onButton1Up()
	turn = false
end

function onKeyDown(key)
	key:lower()
	if key == "y" and fly == false and script.Parent.Parent.Parent.Character:FindFirstChild("Helicopter") ~= nil then
		fly = true
		heli = script.Parent.Parent.Parent.Character.Helicopter
		if heli.Parts:FindFirstChild("Motor1") ~= nil then
			heli.Parts.Motor1.BottomSurfaceInput = "Constant"
		end
		if heli.Parts:FindFirstChild("Motor2") ~= nil then
			heli.Parts.Motor2.BottomSurfaceInput = "Constant"
		end
		if heli.Parts:FindFirstChild("Engine") ~= nil then
			heli.Parts.Engine.BodyVelocity.maxForce = Vector3.new(1e+009,1e+009,1e+009)
			heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,5,0)
			wait(4)
			heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,0,0)
		end
	elseif key == "x" and fly == true then
		fly = false
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.maxForce = Vector3.new(0,0,0)
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,0,0)
				
			end
			if heli.Parts:FindFirstChild("Motor1") ~= nil then
				heli.Parts.Motor1.BottomSurfaceInput = "NoInput"
			end
			if heli.Parts:FindFirstChild("Motor2") ~= nil then
				heli.Parts.Motor2.BottomSurfaceInput = "NoInput"
			end
		end
	elseif key == "w" and fly == true then
		hover = false
		while fly == true do
			if hover == false then
				if heli ~= nil then
					if heli.Parts:FindFirstChild("Engine") ~= nil then
						heli.Parts.Engine.BodyVelocity.velocity = heli.Parts.Engine.CFrame.lookVector * a
					end
				end
			end
			wait(0.1)
		end
	elseif key == "s" and fly == true then
		hover = true
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,0,0)
			end
		end
	elseif key == "d" then
		if a < 100 then
			a = a + 5
		end
	elseif key == "a" then
		if a > 5 then
			a = a - 5
		end
	elseif key == "f" and fly == true then
		if fire == true then
			fire = false
			local gun1 = heli.Parts:FindFirstChild("Gun1")
			local gun2 = heli.Parts:FindFirstChild("Gun2")
			local gun3 = heli.Parts:FindFirstChild("Gun3")
			local gun4 = heli.Parts:FindFirstChild("Gun4")
			if gun1 ~= nil then
				onFire(gun1)
			end
			wait(0.1)
			if gun2 ~= nil then
				onFire(gun2)
			end
			wait(0.1)
			if gun3 ~= nil then
				onFire(gun3)
			end
			wait(0.1)
			if gun4 ~= nil then
				onFire(gun4)
			end
			wait(1.5)
			fire = true
		end
	elseif key == "e" and fly == true then
		hover = true
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,5,0)
			end
		end
		wait(4)
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,0,0)
			end
		end
	elseif key == "q" and fly == true then
		hover = true
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,-5,0)
			end
		end
		wait(4)
		if heli ~= nil then
			if heli.Parts:FindFirstChild("Engine") ~= nil then
				heli.Parts.Engine.BodyVelocity.velocity = Vector3.new(0,0,0)
			end
		end
	end
end

function onSelect(mouse)
	mouse.Icon = "http://www.roblox.com/asset/?id=8599980"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Button1Up:connect(onButton1Up)
	mouse.KeyDown:connect(onKeyDown)
end

script.Parent.Selected:connect(onSelect)

1 answer

✓ Accepted answer

At the beginning of the script add: Repeat wait() until game.Players.Localplayer.Character . From what I know, scripts in test mode tend to load faster than the actual server can load you. You just have to add some waits until the character has loaded.

This discussion is preserved as it was. New answers, comments, and votes are closed.