Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
you need to use a local script and fire a remote event to a server script and play the sounds there 0fficialHen 5 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)
Ad

Answer this question