LocalScript sends player and character objects instead of sounds?

Hello! I am trying to understand why a remotevent meant to send sounds in a players character returns the character and player objects? Ive attempted to change the order and names of the info sent from the event in the serverscript.

LocalScript

local player = game:GetService("Players").LocalPlayer
local char = player.Character
for x, sound in pairs(char:WaitForChild('HumanoidRootPart'):GetChildren()) do
if sound:IsA("Sound") then
if sound.Name == 'Jumping' then
game:GetService("ReplicatedStorage"):WaitForChild("remotes"):WaitForChild("sound"):FireServer(sound,true)
else
game:GetService("ReplicatedStorage"):WaitForChild("remotes"):WaitForChild("sound"):FireServer(sound,false)
end
end
end

ServerScript

game:GetService("ReplicatedStorage"):WaitForChild("remotes"):WaitForChild("sound").OnServerEvent:Connect(function(el,sound)
if sound == true then
el.Volume = 4
el.SoundId = 'rbxassetid://779912379'
else
print(el:GetFullName())
el:Destroy()
end
end)

The first parameter of OnServerEvent listeners is the player who fired. So el is treated as that first argument

2 Likes

I don’t really understand what you mean by “isteners is the player who fired.”?

That means the ‘el’ in your ServerScript is always the player who fired the RemoteEvent.

This may solve your problem:

game.ReplicatedStorage.remotes.sound.OnServerEvent:Connect(function(player, el, sound)
	if sound == true then	
		el.Volume = 4
		el.SoundId = 'rbxassetid://779912379'		
	else
		print(el:GetFullName())
		el:Destroy()	
	end
end)
1 Like