Ey. Not that good with keydown scripts. Im trying to make it so that when you are driving, if you stop pressing the throttle (W key) then the sound will stop, similar to when you put your foot off the gas when driving, the engine isn't as loud. Not sure what I'm doing wrong.
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.W then script.Parent.Parent.F1.Engine.Playing = true end end) game:GetService("UserInputService").InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.W then script.Parent.Parent.F1.Engine.Playing = false end end)
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.W then script.Parent.Parent.F1.Engine:Play() end end) game:GetService("UserInputService").InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.W then script.Parent.Parent.F1.Engine:Stop() end end)
90% Chance to work.
-- Hope i helped.
---- AIphanium
------ Edited the answer, and also, no need to accept this answer, just edited your script :l
Try checking out :IsKeyDown() event thing..
while wait() do if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W) then if not script.Parent.Parent.F1.Engine.Playing then script.Parent.Parent.F1.Engine:Play() end else script.Parent.Parent.F1.Engine:Stop() end end
You should use :Play() and :Stop()
ex:
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() UIS = game:GetService('UserInputService') Sound = game:GetService('SoundService'):FindFirstChild('Sound') --Remember to define your sound UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.W then Sound:Play()--Remember to define your sound else Sound:Stop()--Remember to define your sound end end) UIS.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.W then Sound:Stop()--Remember to define your sound end end)