Sounds won't play on the server

i’m making hitsounds for my combat system, theres a script in serverscriptservice which is meant to handle the hitsounds but for some reason it doesn’t play any of them

theres one event for client to server sounds and server to server sounds, for players and enemies respectively, the way it works is by getting the sound and the desired parent through the event, then cloning the sound, and setting the clone’s parent to the desired parent

for some reason, both of the sounds (client and server) won’t play
side note, the same script has sounds and effects for parrying and those work fine

code (the script is inside serverscriptservice):

local storage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local remotes = storage:WaitForChild("remotes")
local hitfunc = remotes:WaitForChild("hitfunction")
local hitfuncbind = remotes:WaitForChild("hitfunctionbind")
local hitservertoclient = remotes:WaitForChild("hitservertoclient")
local dmgindicator = remotes:WaitForChild("dmgindicator")
local parryevent = remotes:WaitForChild("parryevent")

local attpart = script:WaitForChild("attpart")
local parryatt = attpart:WaitForChild("parryatt")

local function hitsoundfunc(hitsound, hsparent)
	coroutine.wrap(function()
		if hsparent then
			local newhs = hitsound:Clone()
			newhs.Parent = hsparent
			newhs.Loaded:Wait()
			task.wait(1)
			newhs:Play()
		else
			local newhs = hitsound:Clone()
			newhs.Parent = hitsound.Parent
			newhs.Loaded:Wait()
			task.wait(1)
			newhs:Play()
		end
	end)()
end

hitfunc.OnServerInvoke = function(plr, targetchar, dmg, kbtime, kbdir, kbvel, hitsound, hsparent)
	if targetchar:GetAttribute("dead") or targetchar:GetAttribute("downed") then return end
	if targetchar:FindFirstChildOfClass("Humanoid").Health > 0 then
		hitsoundfunc(hitsound,hsparent)
		if targetchar:GetAttribute("parry") then
			local newpa = parryatt:Clone()
			newpa.Parent = targetchar.Torso
			newpa.parry:Play()
			newpa.impact1:Emit(1)
			newpa.impactfin:Emit(1)
			if game.Players:GetPlayerFromCharacter(targetchar) then
				parryevent:FireClient(game.Players:GetPlayerFromCharacter(targetchar))
				hitservertoclient:FireClient(game.Players:GetPlayerFromCharacter(targetchar), kbtime, kbdir, kbvel, true)
			end
			coroutine.wrap(function()
				task.wait(2)
				newpa:Destroy()
			end)()
		else
			targetchar:FindFirstChildOfClass("Humanoid"):TakeDamage(tonumber(dmg))
			dmgindicator:FireAllClients(dmg, targetchar, plr)
			if game.Players:GetPlayerFromCharacter(targetchar) then
				hitservertoclient:FireClient(game.Players:GetPlayerFromCharacter(targetchar), kbtime, kbdir, kbvel, false)
			end
		end
	end
end

hitfuncbind.OnInvoke = function(targetchar, dmg, kbtime, kbdir, kbvel, hitsound, hsparent)
	if targetchar:GetAttribute("dead") or targetchar:GetAttribute("downed") then return end
	if targetchar:FindFirstChildOfClass("Humanoid").Health > 0 then
		hitsoundfunc(hitsound,hsparent)
		if targetchar:GetAttribute("parry") then
			local newpa = parryatt:Clone()
			newpa.Parent = targetchar.Torso
			newpa.parry:Play()
			newpa.impact1:Emit(1)
			newpa.impactfin:Emit(1)
			if game.Players:GetPlayerFromCharacter(targetchar) then
				parryevent:FireClient(game.Players:GetPlayerFromCharacter(targetchar))
				hitservertoclient:FireClient(game.Players:GetPlayerFromCharacter(targetchar), kbtime, kbdir, kbvel, true)
			end
			coroutine.wrap(function()
				task.wait(2)
				newpa:Destroy()
			end)()
		else
			targetchar:FindFirstChildOfClass("Humanoid"):TakeDamage(tonumber(dmg))
			dmgindicator:FireAllClients(dmg, targetchar, nil)
			if game.Players:GetPlayerFromCharacter(targetchar) then
				hitservertoclient:FireClient(game.Players:GetPlayerFromCharacter(targetchar), kbtime, kbdir, kbvel, false)
			end
		end
	end
end

currently in the code i’m waiting 1 second after it loads to have time to check if playing is enabled in the explorer
i can see both of the sounds in the desired parent in the explorer so they definitely are being created but not played
and ye the sounds being sent from the client and their parent already exist on the server inside a tool

Ok so is the sound In the script or in something in the workspace?

Cause this might be the problem here.
The sound will only play if it is in an object in the workspace(Unless its a local script).

If this is the case I recommend cloning the sound, putting it into what you hit, then playing it there.
Then wait till the sound is over, and remove the sound!

like i said, the sound clone is being sent into the parent, and i know for a fact it’s in the parent since i see it in the explorer

Ok then. What are the sounds properties?
Could I look at them(Just trying to narrow down what is happening)


these are the properties for the hit sound used for the heavy attack inside the fists tool
the rest of the attack properties are basically the same

just realized the image doesn’t show the routing section, there is no soundgroup selected

Ok first. Try putting a print after when you play the sound to make sure it is playing. and do this so if it does play you can tell for sure that it did.

yourSound.Ended:Wait()
print('Sound is over. So it did play')

if this does not work that means that the sound is not playing.
And in that case I will not know how to help you(Cause I am dumb lol)

Hope this works!

If it does print BTW. That probably means you just cant here it.
Also your roblox sound Is on right?

good idea, i’ll try it out

and yes, sounds are on, i can hear the rest of the sounds being played

1 Like

i made it print after it waits for it to load, and it didn’t print which made me realize lol

apparently it was cause i was waiting for it to load when it was already loaded, so it was waiting forever

i removed the loading part and it works fine

ty for your help

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.