Currently, I’m trying to play a sound in a local script by detecting whether a remote event had been fired after the player’s sword had hit a humanoid. The local script does detect the event, however, the sound does not play. Any help?
Local Script
script.MeleeDMG.OnClientEvent:connect(function(Player, Type)
if Type == "PlayHit" then
local soundSwordFHit = h.OneHanded.SwordOneHit
soundSwordFHit.SoundId = "rbxassetid://935843979"
soundSwordFHit:Play()
end
if Type == "PlayBlocked" then
local soundSwordOneBlocked = h.OneHanded.SwordOneBlocked
local sound = math.random(1,2)
if sound == 1 then
soundSwordOneBlocked.SoundId = "rbxassetid://211059855"
soundSwordOneBlocked:Play()
else
soundSwordOneBlocked.SoundId = "rbxassetid://357622136"
soundSwordOneBlocked:Play()
end
end
end)
Server Script
if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Humanoid.Blocking.IsBlockingLeft.Value then
hit.Parent.Humanoid:TakeDamage(DMG)
script.Parent:FireClient(Player, "PlayHit")
elseif hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Blocking.IsBlockingLeft.Value then
if (lookVector:Dot(Position) < 1) then
hit.Parent.Humanoid:TakeDamage(DMG)
script.Parent:FireClient(Player, "PlayHit")
else
script.Parent:FireClient(Player, "PlayBlocked")
end
end
Edit
The local script is returning “Type” as a nil value?
I’m trying to find a way to play a sound so that people far away can’t hear it. When played on the server script, the volume doesn’t seem to change even when I had lowered the emitter size and what not.
I’m assuming when played in a local script the sound is only played through the one player?
If that is the case then you are running some code that is not what you have shown us. Please highlight line 34 of your code where the error is occurring
Yes I understand, but you detected the hit from the server script. That is why I asked what is the Player you passed in the FireClient referencing to, because you don’t show it. I am thinking that you are not passing the actual player in this case.
What is parent of sound? If is player, then i dont know why sound dosent play, if its script then, well you have to place sound in player not in script, if nill then sound must be in player.