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)
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)