How Can I Make A Vehicle Control Script

Hello,

I’m making a vehicle in Studio by using seat and hinges.(Not VehicleSeat Because I tried this way but it didn’t worked.)

For Controlling,I tried use UserInputService method in LocalScript.

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)

if key.Keycode == Enum.KeyCode.W then
	--vehicle controlling codes here
end

end)

When I using this script into the seat,It doesn’t print anything at all,but When I using this script into the StarterGUI It starts to work! (I think UserInputService is only for Gui Scripting)

I want to know which methods should I use?

2 Likes

Local scripts do not run when it is a descendant of the workspace (descendant of a character is an exception)

You can place a local script in either:

  • StarterGui
  • StarterPlayerScripts
  • StarterCharacterScripts
  • StarterPack
3 Likes

Finally, I made the script and my car is working!

Car Driver Script

local player = nil
local c = Instance.new(“StringValue”)
------------------------------------------------
script.Parent.ChildAdded:Connect(function()

player = script.Parent.Occupant.Parent

scr = script.KeycodeScript:Clone()
scr.Parent = player
scr.Disabled = false

scr.Checker.OnServerEvent:Connect(function(plr,code)
print(code)
if code == "W" then
	script.Parent.Parent.Shaft.Wheels.A.AngularVelocity = 30
	script.Parent.Parent.Shaft.Wheels.B.AngularVelocity = -30
else
	script.Parent.Parent.Shaft.Wheels.A.AngularVelocity = 0
	script.Parent.Parent.Shaft.Wheels.B.AngularVelocity = 0
end

end)

end)
------------------------------------------------
script.Parent.Parent.ChildRemoved:Connect(function()
scr:Destroy()
end)
KeyChecker Script

local UIS = game:GetService(“UserInputService”)

UIS.InputBegan:Connect(function(code)

if code.KeyCode == Enum.KeyCode.W then
	script.Checker:FireServer("W")
end
end)

UIS.InputEnded:Connect(function()
script.Checker:FireServer("")
end)

Thank For Your Help! @wevetments

6 Likes