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

Could anyone assist me with making a sound loop until a user presses c again?

``Okay so, I'm making indicators on a vehicle and I want the sound to repeat until the user presses "c" again.

This is the code at the moment;

local mouse = game.Players.LocalPlayer:GetMouse()
wait(1)
mouse.KeyDown:connect(function(key)
                if key=="c" then
		script.Parent.rightIndicatorvalue.Value:FireServer(mouse)
		script.Sound:Play()
	end
	end)

If anyone could help that would be awesome

1 answer

✓ Accepted answer

Dont use Mouse.Keydown use UserInputService

UserInputService = game:GetService("UserInputService")
Looping == false
UserInVeichle = false --Change this value for when the exit and enter the veichle.
UserInputService.InputBegan:Connect(function(key, gameProcessed)
if key.Keycode == Enum.Keycode.C then --Check if keycode = the enum keycode of c.
if gameProcessed then --Check if game took input (If chatting game would not take input)
if UserInVeichle then --Checking if user is still in car
if not Looping then --Check if sound is still looping
script.Sound:Play()
end
script.Sound.Looped = not Looping --If it is looping it would change it to be not Looping
Looping = not Looping --Same time as last time, Its like opposites.
end
end
end)

Hope this helped!

1 comment

0

Thanks mate!

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