Hello, i need help with UserInputService. the script is inside a car's vehicle seat. When i test the game normally, it doesnt run the script. but if i enter the car, the script runs as its supposed to be. But if i exit the car, UserInputService is still runnng. Whats the problem, how can i stop it form doing that? heres my script:
local debounce = true
local uis = game:GetService("UserInputService")
local h1 = script.Parent.Parent.H1
local h2 = script.Parent.Parent.h2
local b1 = script.Parent.Parent.b1
local b2 = script.Parent.Parent.b2
script.Parent.Changed:connect(function()
if script.Parent.Throttle == 0 or script.Parent.Throttle == -1 then
b1.PointLight.Enabled = true
b2.PointLight.Enabled = true
script.Parent.Value.Value = 20
end
if script.Parent.Throttle == 1 or script.Parent.ThrottleFloat == 1 then
b1.PointLight.Enabled = false
b2.PointLight.Enabled = false
script.Parent.Value.Value = 300
end
end)
script.Parent.ChildRemoved:Connect(function()
b1.PointLight.Enabled = false
b2.PointLight.Enabled = false
debounce = true
script.Disabled = true
end)
script.Parent.ChildAdded:Connect(function()
script.Disabled = false
script.Parent.Sound:Play()
debounce = false
uis.InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.L then
h1.SpotLight.Enabled = not h1.SpotLight.Enabled
h2.SpotLight.Enabled = not h2.SpotLight.Enabled
end
end)
uis.InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.X and not debounce then
debounce = true
local d = Instance.new("BodyForce")
d.Force = Vector3.new(0,50000,0)
d.Parent = script.Parent.Parent.base
local b = Instance.new("BodyGyro")
b.P = Vector3.new(5000)
b.D = Vector3.new(10000)
b.MaxTorque = Vector3.new(500, 100, 100)
b.Parent = script.Parent.Parent.base
wait(0.5)
d:Destroy()
b:Destroy()
wait(3)
debounce = false
end
end)
end)

1 comment
Wow, thank you so much, it worked! I really need to learn how to use return.