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

How to make a sound play on the humanoid root part when the player presses shift?

I tried to make a keycode script by upon pressing shift a running sound will play and all the other players will hear it. I'm not sure if i need to extend this question.

1 comment

0

you need to use a local script and fire a remote event to a server script and play the sounds there

1 answer

local script

local uis = game:GetService("UserInputService")
local playsound = game.ReplicatedStorage.PlaySound--make a remote event named PlaySound
local play = true
uis.InputBegan:Connect(function(input,process)
if process then return end
if input.KeyCode == Enum.KeyCode.Shift then
play = true
playsound:FireServer(play)
end)
uis.InputEnded:Connect(function(in)
if in.KeyCode == Enum.KeyCode.Shift then
play = false
playsound:FireServer(play)

end)

server script:

local playsound = game.ReplicatedStorage.PlaySound
local sound = game.ReplicatedStorage.Dababy -- your music
sound.Looped = false
playsound.OnServerEvent:Connect(function(plr,bool)
if not sound.IsLoaded then
sound.Loaded:Wait()
end
if bool then
sound:Play()
elseif bool == false then
sound:Stop()
end
end)

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