I have been trying to get sounds for my tool to play on the server but I cant seem to figure it out, the client side is outputting remote events but no matter what I try I cant seem to get the server script to respond in any type of way
Here is my local script thats firing the remote events
local toolName = "AK-12" -- or "Glock17"
local tool = game.Players.LocalPlayer.Backpack:FindFirstChild(toolName)
local position = tool and tool.Handle.Position
local muzzleFlashEvent = eventsFolder:WaitForChild("MuzzleFlashEvent")
local function playMuzzleEffect()
muzzleFlashEvent:FireServer(tool.AK12.Muzzle.Part.Position)
end
local function fireFiringSound(toolName)
local position = tool.AK12.Muzzle.Part.Position -- Adjust this line according to your tool structure
ReplicatedStorage.Events.FiringSoundEvent:FireServer(toolName, game.Players.LocalPlayer, position)
print("Local Firing input detected")
end
local function fireReloadSound(toolName)
local position = tool.Handle.Position -- Adjust this line according to your tool structure
ReplicatedStorage.Events.ReloadSoundEvent:FireServer(toolName, game.Players.LocalPlayer, position)
print("Local Reloading input detected")
end
local function fireClickSound(toolName)
local position = tool.Handle.Position -- Adjust this line according to your tool structure
ReplicatedStorage.Events.ClickSoundEvent:FireServer(toolName, game.Players.LocalPlayer, position)
print("Local Clicking input detected")
end
and heres the server script that should be receiving them
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
print("Server input detected")
-- Function to play AK-12 sounds
local function playAK12Sounds(parent, position)
local soundFolder = ReplicatedStorage.Sounds.AK12
local fireRate = 0.3 -- Time between shots in seconds
local boltcomboPlaybackSpeed = 0.5 / fireRate
local gunshotPlaybackSpeed = 0.5 / fireRate
if not soundFolder then
warn("Sound folder for AK-12 not found.")
return
else
print("Server AK12 detected")
end
local function playReload()
print("Server ReloadSounds loaded")
local sounds = {}
task.wait(0.37)
sounds.bolt_out = soundFolder:FindFirstChild("bolt_out")
task.wait(0.40)
sounds.mag_out = soundFolder:FindFirstChild("mag_out")
task.wait(0.44)
sounds.pocket = soundFolder:FindFirstChild("pocket")
task.wait(0.37)
sounds.mag_in = soundFolder:FindFirstChild("mag_in")
return sounds
end
local function playFiring()
print("Server Firing loaded")
local sounds = {}
task.wait(0.07)
sounds.gunshot = soundFolder:FindFirstChild("gunshot")
sounds.boltcombo = soundFolder:FindFirstChild("boltcombo")
if sounds.boltcombo and sounds.gunshot then
sounds.boltcombo.PlaybackSpeed = boltcomboPlaybackSpeed
sounds.boltcombo.Looped = true
sounds.gunshot.Looped = true
end
return sounds
end
local function playClick()
print("Server Clicking loaded")
local sounds = {}
task.wait(0.07)
sounds.boltcombo = soundFolder:FindFirstChild("boltcombo")
return sounds
end
return { playReload(), playFiring(), playClick(), position = position }
end
-- Function to play Glock17 sounds
local function playGlock17Sounds(parent, position)
local soundFolder = ReplicatedStorage.Sounds.Glock17
if not soundFolder then
warn("Sound folder for Glock17 not found.")
return
end
local function playReload()
local sounds = {}
sounds.mag_in = soundFolder:FindFirstChild("mag_in")
sounds.mag_out = soundFolder:FindFirstChild("mag_out")
return sounds
end
local function playFiring()
local sounds = {}
sounds.gunshot = soundFolder:FindFirstChild("gunshot")
return sounds
end
local function playClick()
local sounds = {}
sounds.bolt_in = soundFolder:FindFirstChild("bolt_in")
sounds.bolt_out = soundFolder:FindFirstChild("bolt_out")
return sounds
end
return { playReload(), playFiring(), playClick(), position = position }
end
-- Function to play sounds based on the tool name
local function playToolSounds(toolName, parent, position)
if toolName == "AK-12" then
print("Server AK12 Sounds loaded")
return playAK12Sounds(parent, position)
elseif toolName == "Glock17" then
return playGlock17Sounds(parent, position)
else
warn("No sound function found for "..toolName)
return
end
end
-- Function to play sounds from a table
local function playSounds(sounds, parent, position)
local soundInstances = {}
for i, sound in pairs(sounds) do
if sound then
local soundInstance = sound:Clone()
soundInstance.Parent = parent
soundInstance.Position = position
soundInstance:Play()
table.insert(soundInstances, soundInstance)
print("Server Sounds Played")
end
end
return soundInstances
end
-- Function to stop sounds
local function stopSounds(soundInstances)
for _, soundInstance in pairs(soundInstances) do
soundInstance:Stop()
soundInstance:Destroy()
print("Server Sounds Stopped")
end
end
-- Remote function to handle firing sounds
local function fireSound(toolName, player)
local character = player.Character
if not character then return end
local tool = character:FindFirstChild(toolName)
if not tool then return end
local position = tool.Handle.Position
local firingSounds = playToolSounds(toolName, tool, position)
local soundInstances = playSounds(firingSounds, SoundService, position)
-- Sound will play for 2 seconds, adjust according to your needs
task.wait(2)
-- Stop and destroy the sounds
stopSounds(soundInstances)
print("Server Fire Sounds Fired")
end
-- Remote function to handle reload sounds
local function reloadSound(toolName, player)
local character = player.Character
if not character then return end
local tool = character:FindFirstChild(toolName)
if not tool then return end
local position = tool.Handle.Position
local reloadSounds = playToolSounds(toolName, tool, position)
local soundInstances = playSounds(reloadSounds, SoundService, position)
-- Sound will play for 2 seconds, adjust according to your needs
task.wait(2)
-- Stop and destroy the sounds
stopSounds(soundInstances)
print("Server Reload Sounds Fired")
end
-- Remote function to handle clicking sounds
local function clickSound(toolName, player)
local character = player.Character
if not character then return end
local tool = character:FindFirstChild(toolName)
if not tool then return end
local position = tool.Handle.Position
local clickSounds = playToolSounds(toolName, tool, position)
local soundInstances = playSounds(clickSounds, SoundService, position)
-- Sound will play for 2 seconds, adjust according to your needs
task.wait(2)
-- Stop and destroy the sounds
stopSounds(soundInstances)
print("Server Reload Sounds Fired")
end
-- Event to play sounds when the FiringSoundEvent is fired
ReplicatedStorage.Events.FiringSoundEvent.OnServerEvent:Connect(fireSound)
-- Event to play sounds when the ReloadSoundEvent is fired
ReplicatedStorage.Events.ReloadSoundEvent.OnServerEvent:Connect(reloadSound)
-- Event to play sounds when the ClickSoundEvent is fired
ReplicatedStorage.Events.ClickSoundEvent.OnServerEvent:Connect(clickSound)
for this script just ignore the glock17 part as im only testing with the AK12, im trying to have a setup where I have the script grab the sounds and play them in order based on the guns name and folder name, Im currently getting no Syntax issues and Iâve made sure that everything is named correctly