Unable to play sound through fireclient

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?

Try putting the id in the propertires, and when you define the sound you should add a clone:()

Edit maybe it’s the sound i dont see anything wrong

The sound seems to play when I remove the “if type then” statements from the local script. However, I’d prefer another solution to this.

Your OnClientEvent function argument should not include the player, just the type.

script.MeleeDMG.OnClientEvent:Connect(function(Type)

I have already tried that, it returns with “Unable to cast value to Object”
https://gyazo.com/03bfbb4a71972144ea8af6a543394f34

Nvm, Why are you trying to play this sound client sided?

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?

It look like there is a problem with your server passing the Player. Can you show us what is the Player in your server script?

I’m unsure what you mean, but:
image

image
Local Script

Server Script

Sorry for not making it clear. I mean the Player that you pass on the :FireClient event. In here

script.Parent:FireClient(Player, "PlayBlocked")

Maybe after validating the Homanoid part try to pass this

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent:FireClient(player, "PlayBlocked")

I may be wrong but, in local scripts you cant use:

.OnClientEvent

that script is client, instead use:

.OnServerEvent

or something like that, .OnClientEvent in local scripts makes them work bit broken (at last when i did it)

You just need to remove Player from the LocalScript so it becomes function(Type)

As mentioned before, this will come out with “Unable to cast value Object”

I am playing the sound in the player who has hit the humanoid. Would I need to specify player if it would just be me saying “local player = 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.

Line 34 is just me firing the remote event

script.Parent:FireClient(Player, "PlayBlocked")

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.

But that is from the server script. You should not remove Player from the server script. You should only remove it from the LocalScript

1 Like

Ah I see, but when I print Player the output is the player?
https://gyazo.com/4e226a52f9e27813e93d1dbff0065b09