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