How do I make a playing sounds script by pressing the keys?

I’m struggling with scripting for ages. What I want to achieve is to play a sound when holding a shift key and I seem to be very struggling to do it by myself. If anyone know how to do it, would you mind helping me getting the script working. I would be very appreciated! Thank you!

Also how do you do it with remote event?

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input,isTyping)
	if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
		YourSound:Play()
	end
end)
1 Like
--me just used free model script: sprint script you may find it in ToolBox. (Place in StarterGui
repeat wait() until game.Players.LocalPlayer

m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)--Key is holding (Shift)
	if key == "0" then -- 0 is Shift Button
 script.Parent.Sound:Play()--change Sound to your sound name
	end
end)

m.KeyUp:connect(function(key)--Key is not more holding (Shift)
	if key == "0" then
		script.Parent.Sound:Stop() 
	end
end)
2 Likes

Thank you so much for the script!

Thanks alot! This would be very helpful for my game.

Also I have a question. How do you do it with remote event?

read this. Its may be helpful