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

What would I need to change?

I want to script a bike for my latest game so that it will be supported on the Iphone/Android devices (Yes, I said Android! I found a WORKING .apk file)

All I need to know is what are the inputs Roblox see when on these devices?

Here is the basic bikes script.

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")

EngineSound = Handle:WaitForChild("Running")
HonkSound = Handle:WaitForChild("Honk")

HoldAnim = Tool:WaitForChild("HoldAnim")

SoundInput = Tool:WaitForChild("SoundInput")

Left = false
Right = false
Up = false
Down = false

LastSpace = 0

SmokePart = Instance.new("Part")
SmokePart.Transparency = 1
SmokePart.Size = Vector3.new(0, 0, 0)

ExhaustSmoke = Instance.new("Smoke")
ExhaustSmoke.Parent = SmokePart
ExhaustSmoke.Size = 0.1
ExhaustSmoke.RiseVelocity = 0.01
ExhaustSmoke.Color = Color3.new(0.5, 0.5, 0.5)

Acceleration = 10
Deceleration = 10
TurnAlpha = 0.30
AlphaDampening = 0.2

Equipped = false

LastPosition = nil
ActualVelocity = Vector3.new(0, 0, 0)

FrontWheel = Instance.new("Part")
FrontWheel.FormFactor = "Custom"
FrontWheel.CanCollide = false
FrontWheel.Size = Vector3.new(0, 0, 0)

WheelMesh = Instance.new("SpecialMesh")
WheelMesh.TextureId = "http://www.roblox.com/asset/?id=157152110"
WheelMesh.Scale = Vector3.new(1, 1, 1)
	
Light = FrontWheel:Clone()

local BackWheel = FrontWheel:Clone()

CurrentSpeed = 0
TurnSpeed = 0
TurnSpeedAim = 5

function ThrustUpdater()
	while Equipped do
		local Direction = Torso.CFrame.lookVector
		Direction = Vector3.new(Direction.x, 0, Direction.z).unit
		ThrustForce.velocity = (Direction * CurrentSpeed)
		EngineSound.Pitch = (1 + (math.abs(CurrentSpeed / 50) * 1))
		
		if FrontMotor then
			FrontMotor.DesiredAngle = (999999999 * (-CurrentSpeed / math.abs(CurrentSpeed)))
			FrontMotor.MaxVelocity = (CurrentSpeed / 250)
			if BackMotor then 
				BackMotor.DesiredAngle = FrontMotor.DesiredAngle
				BackMotor.MaxVelocity = FrontMotor.MaxVelocity	
			end	
		end
		
		RotationForce.angularvelocity = Vector3.new(0, TurnSpeed, 0)
		if math.abs(TurnSpeed) > AlphaDampening	 then
			TurnSpeed = (TurnSpeed - (AlphaDampening * (math.abs(TurnSpeed) / TurnSpeed)))
		else 
			TurnSpeed = 0		
		end
		local LeanAmount = (-TurnSpeed * (math.pi / 6) / 4)
		
		if not Forwards or Back then
			CurrentSpeed = (CurrentSpeed * 0.99	)		
		end		
		
		local XZAngle = math.atan2(Torso.CFrame.lookVector.z, 0, Torso.CFrame.lookVector.x)
		TurnGyro.cframe = CFrame.Angles((LeanAmount * Direction.x), 0, (LeanAmount * Direction.z))
		ExhaustSmoke.Opacity = (math.min(math.abs(CurrentSpeed), 10) / 10) * 0.5
		if LastPosition then
			local NPos = Vector3.new(Torso.CFrame.p.x, 0, Torso.CFrame.p.z)
			local MySpeed = Vector3.new(FakeHandle.Velocity.X, 0, FakeHandle.Velocity.Z).magnitude
			local VelocityDifference = math.abs((MySpeed - (ThrustForce.velocity.magnitude)))
			if MySpeed > 3 and ThrustForce.velocity.magnitude > 3 and VelocityDifference > (0.7 * ThrustForce.velocity.magnitude) then
				CurrentSpeed = (CurrentSpeed * 0.9)
			end
		end
		LastPosition = Vector3.new(Torso.CFrame.p.x, 0, Torso.CFrame.p.z)
		wait(1 / 60)
	end
end

function GetTotalMass(Parent)
	local TotalMass = 0
	for i, v in pairs(Parent:GetChildren()) do
		if v:IsA("BasePart") then
			TotalMass = TotalMass + v:GetMass()
		end
		GetTotalMass(v)
	end
	return TotalMass
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	Torso = Character:FindFirstChild("Torso")
	if not Player or not Humanoid or Humanoid.Health == 0 or not Torso then
		return
	end
	wait()
	Mouse.KeyDown:connect(function(Key)
		local Key = Key:lower()
		if Key == "w" then
			Forwards = true
			while Forwards do
				CurrentSpeed = math.min(70, (CurrentSpeed + (Acceleration * (1 / 30))))
				wait(1 / 30)
			end
		elseif Key == "a" then
			Left = true
			while Left do
				TurnSpeed = math.min(5, (TurnSpeed + (TurnAlpha)))
				wait(1 / 30)
			end
		elseif Key == "s" then
			Back = true
			while Back do
				if CurrentSpeed > 0 then
					CurrentSpeed = math.max(-20, (CurrentSpeed - (Deceleration * 2.8 * (1 / 30))))
				else
					CurrentSpeed = math.max(-20, (CurrentSpeed - (Deceleration * (1 / 30))))
				end
				wait(1 / 30)
			end
		elseif Key == "d" then
			Right = true
			while Right do
				TurnSpeed = math.max(-5, (TurnSpeed - (TurnAlpha)))
				wait(1 / 30)
			end
		elseif Key == " " then
			if (LastSpace == 0 or (tick() - LastSpace) > 1.9) then
				LastSpace = tick()
				local BodyForce = Instance.new("BodyForce")
				BodyForce.force = Vector3.new(0, (((GetTotalMass(Character) * 196.20) * 4) * 4), 0)
				BodyForce.Parent = FakeHandle
				wait(0.1)
				BodyForce:Destroy()
			end
		elseif Key == "x" then
			SpotLight.Enabled = not SpotLight.Enabled
		elseif Key == "h" then
			SoundInput.Value = "Name = " .. HonkSound.Name .. ", " .. "IsPlaying = true"
		end
	end)
	
	Mouse.KeyUp:connect(function(Key)
		local Key = Key:lower()
		if Key == "w" then
			Forwards = false
		elseif Key == "a" then
			Left = false
		elseif Key == "s" then
			Back = false
		elseif Key == "d" then
			Right = false	
		end
	end)
	
	FakeHandle = Handle:Clone()
	FakeHandle.Name = "FakeHandle"
	FakeHandle:WaitForChild("Mesh").MeshId = "http://www.roblox.com/asset/?id=158071925"
	FakeHandle.Parent = Tool
	FakeHandle.CFrame = Torso.CFrame
	Handle.Transparency = 1
	
	FrontWheel.Parent = FakeHandle
	FrontMotor = Instance.new("Motor6D")
	FrontMotor.C0 = CFrame.Angles(0, math.pi / 2, 0) + Vector3.new(0, - 1.1, - 2.85)
	FrontMotor.C1 = CFrame.Angles(0, - math.pi / 2, 0)
	FrontMotor.Part0 = FakeHandle
	FrontMotor.Part1 = FrontWheel
	FrontMotor.Parent = FakeHandle
	FrontWheelMesh = WheelMesh:Clone()
	FrontWheelMesh.MeshId = "http://www.roblox.com/asset?id=157152145"
	FrontWheelMesh.Parent = FrontWheel
					
	BackWheel.Parent = FakeHandle
	BackMotor = Instance.new("Motor6D")
	BackMotor.C0 = CFrame.Angles(0, math.pi / 2, 0) + Vector3.new(0, - 1.1, 2.9)
	BackMotor.C1 = CFrame.Angles(0, - math.pi / 2, 0)
	BackMotor.Part0 = FakeHandle
	BackMotor.Part1 = BackWheel
	BackMotor.Parent = FakeHandle
	BackWheelMesh = WheelMesh:Clone()
	BackWheelMesh.MeshId = "http://www.roblox.com/asset?id=157152190"
	BackWheelMesh.Parent = BackWheel
				
	Light.Parent = FakeHandle
	LightWeld = Instance.new("Weld")
	LightWeld.C0 = CFrame.new(0, 0, 0, 0, 0, - 1, 0, 1, 0, 1, 0, 0)
	LightWeld.C1 = CFrame.new(-0.140708923, -0.749996185, -0.9377985, -1.63912773e-007, -1.27675008e-008, -1.00000024, -2.05633661e-008, 0.99999994, 3.65663944e-009, 0.999999881, 5.65337004e-008, -7.4505806e-008)
	LightWeld.Part0 = FakeHandle
	LightWeld.Part1 = Light
	LightWeld.Parent = FakeHandle
	
	SpotLight = Instance.new("SpotLight")
	SpotLight.Brightness = 5
	SpotLight.Angle = 45
	SpotLight.Color = Color3.new(255 / 255, 252 / 255, 153 / 255)
	SpotLight.Parent = Light
	SpotLight.Range = 40
			
	CurrentSpeed = 0
	TurnSpeed = 0
	Equipped = true
			
	Handle.CFrame = Torso.CFrame
	Humanoid.PlatformStand = true
			
	RotationForce = Instance.new("BodyAngularVelocity")
	RotationForce.maxTorque = Vector3.new(0, math.huge, 0)
	RotationForce.angularvelocity = Vector3.new(0, 0, 0)
	RotationForce.Parent = Torso
	
	ThrustForce = Instance.new("BodyVelocity")
	ThrustForce.maxForce = Vector3.new(math.huge, 0, math.huge)
	ThrustForce.velocity = Vector3.new(0, 0, 0)
	ThrustForce.P = 100
	ThrustForce.Parent = FakeHandle
			
	TurnGyro = Instance.new("BodyGyro")
	TurnGyro.maxTorque = Vector3.new(5000, 0, 5000)
	TurnGyro.P = 300
	TurnGyro.D = 100
	TurnGyro.Parent = Torso
			
	Spawn(ThrustUpdater)
	
	if HoldAnimTrack then
		HoldAnimTrack:Stop()
	end
	
	HoldAnimTrack = Humanoid:LoadAnimation(HoldAnim)
	HoldAnimTrack:Play()
	
	Spawn(function()
		Torso.Anchored = true
		Torso.CFrame = Torso.CFrame + Vector3.new(0, 3, 0)
		
		TorsoWeld = Instance.new("Weld")
		TorsoWeld.C0 = CFrame.Angles(0, 0, 0) + Vector3.new(0, -1.6, -0.7)
		TorsoWeld.Part0 = Torso
		TorsoWeld.Part1 = FakeHandle
		TorsoWeld.Parent = FakeHandle
		FakeHandle.CanCollide = true
				
		wait(0.1)
		
		FakeHandle.CanCollide = true
		Torso.Anchored = false
		Torso.CFrame = Torso.CFrame + Vector3.new(0, 3, 0)
	end)

	SmokePart.Parent = FakeHandle

	local TWeld = Instance.new("Weld")
	TWeld.C0 = CFrame.new(0, -0.85, -4, 1, 0, 0, 0, 1, 0, 0, 0, 1)
	TWeld.Part0 = SmokePart
	TWeld.Part1 = FakeHandle
	TWeld.Parent = SmokePart
	
	SoundInput.Value = "Name = " .. EngineSound.Name .. ", " .. "IsPlaying = true"
	Humanoid.WalkSpeed = 0

end


function Unequipped()
	Equipped = false
	if SmokePart then
		SmokePart.Parent = nil
	end
	if FakeHandle then
		FakeHandle:Remove()
		FakeHandle = nil
	end
	Handle.Transparency = 0
	Forwards = false
	Left = false
	Back = false
	Right = false	
	if RotationForce then
		RotationForce:Destroy()
	end
	if ThrustForce then
		ThrustForce:Destroy()
	end
	if TurnGyro then
		TurnGyro:Destroy()
	end
	if HoldAnimTrack then
		HoldAnimTrack:Stop()
	end
	if TorsoWeld then
		TorsoWeld:Destroy()
	end 
	if EngineSound then
		SoundInput.Value = "Name = " .. EngineSound.Name .. ", " .. "IsPlaying = false"
	end
	Humanoid.WalkSpeed = 16
	Humanoid.PlatformStand = false
end

Tool.Unequipped:connect(Unequipped)
Tool.Equipped:connect(Equipped)

1 answer

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