Is something wrong with my remote event?

can someone help, im trying to make it so, if you press F, a animation plays and an audio queue from the humanoid root part of the local player who pressed it. The problem is that when another player presses it, it cancels the previous’ persons audio and it plays for the person who pressed it. I dont know if its my remote event?I have a script that automatically sends the sound from repicated storage to the hrp so i dont think yall need that. Here are my 2 remaining scripts:
local script in startercharacterscript:

local UserInputService = game:GetService("UserInputService")
local animation = script:WaitForChild("Animation")

    
    local player = game.Players.LocalPlayer
    local character = player.Character
    local humanoid = character.Humanoid
    local animation = humanoid:LoadAnimation(animation)
local soundinhuman = character.HumanoidRootPart:WaitForChild("Sound")
local remote = game.ReplicatedStorage:WaitForChild("EmoteEvent")

UserInputService.InputBegan:Connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.F then
        remote:FireServer()
        
        animation:Play()
        

        end
        
            
    end)


script in server script service:

local Players = game:GetService("Players")
local EmoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("EmoteEvent")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Character) 
        EmoteEvent.OnServerEvent:Connect(function()
            
            local SoundtoPlay = Character:WaitForChild("HumanoidRootPart"):WaitForChild("Sound") 
            
            SoundtoPlay:Play()
            
        end)
            
        end)    
        
    end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Use the Player parameter of OnServerEvent instead. The reason it does that is when a player joins, it fires/activates the function connected to PlayerAdded, meaning the Sound playing only works for the recently joined player.

script in sever script service:

local EmoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("EmoteEvent")

EmoteEvent.OnServerEvent:Connect(function(Player)
   local Character = Player.Character
   if not Character or not Character.Parent then return end
   
   local SoundtoPlay = Character:WaitForChild("HumanoidRootPart"):WaitForChild("Sound") 
   
   SoundtoPlay:Play()
end)
1 Like

<3 thanks for explanation as well!

1 Like

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