I made a tool that plays a sound when you click a key in your keyboard (Q or E) but players cant hear the sounds. How do I fix that? the script is this (its a local script):
player = game.Players.LocalPlayer tool = script.Parent tool.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "q" then wait (0) script.Sound1:Play() end if key == "e" then wait (0) script.Sound2:Play() end end) end)
-- Server Script Named "server": local remote = Instance.new("RemoteEvent") remote.Name = "PlaySound" remote.Parent = script remote.OnServerEvent:Connect(function(player, sound) if sound.ClassName == "Sound" then sound:Play() end end) -- Server Script END -- LocalScript: player = game.Players.LocalPlayer tool = script.Parent tool.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "q" then wait (0) script.Parent.server.PlaySound:FireServer(script.Sound1) end if key == "e" then wait (0) script.Parent.server.PlaySound:FireServer(script.Sound2) end end) end) -- LocalScript END
Since this is in a local script, it is required to use a remote event. Insert a remote event in the replicated storage and name it whatever.
Then copy this: LOCAL SCRIPT
local FE = game.ReplicatedStorage.RemoteEvent --Name of the remote event local sound = script.Sound --Or whatever name you gave it tool.Equipped:Connect(function(mouse) mouse.KeyDown:Connect(function(key) if key == "q" or key == "e" then FE:FireServer(sound) end end) end)
SERVER SCRIPT
local FE = game.ReplicatedStorage.RemoteEvent --name of the remote event FE.OnServerEvent:Connect(function(player,sound) sound:Play() end)
Though, I would recommend that you switch to UserInputService since it is simpler to use. If you decide to use UserInputService then copy this code:
LOCAL SCRIPT V2
local FE = game.ReplicatedStorage.RemoteEvent --name of the remote event local uis = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local enabled = false local tool = script.Parent local sound = scirpt.Sound --Or whatever name you gave it tool.Equipped:Connect(function() enabled = true end) tool.Unequipped:Connect(function() enabled = false end) uis.InputBegan:Connect(function(key,chatting) if key.KeyCode == Enum.KeyCode.E or key.KeyCode == Enum.KeyCode.Q and chatting == false and enabled == true then FE:FireServer(sound) end end)
There are many solutions to this, but I think this will help you.