#client not receiving proper data through remote event (server -> client)

1 messages · Page 1 of 1 (latest)

mystic eagle
#

(kinda a repost cuz last post got buried)
basically, im tryna make a system that allows the server to request that a specific player's client delete fx just for them (in this specific context it's to delete a gunshot sound effect for the player so it sounds good on their client), but whenever the server fires the remote event and transmits the sound (which in this case is a part, it's supposed to be a positional sound effect), the client recieves a nil value and prints nil

the event is under replicated storage, the localscript is under startergui, and the server script is a function in a module script being executed by a tool's server script

server:

if delForPlr then serverToClient.deleteFXforPlr:FireClient(plr,sound) end

client:

events.deleteFXforPlr.OnClientEvent:Connect(function(delete)
    print(delete)
end)
minor iris
#

Hello !

#

You need to make sure the sound (or the part it's inside) is parented to a replicated container, like Workspace, before trying to reference it on the client.

#
if delForPlr then
    if sound:IsDescendantOf(game.Workspace) or sound:IsDescendantOf(game.ReplicatedStorage) then
        serverToClient.deleteFXforPlr:FireClient(plr, sound)
    else
        warn("Sound not replicated; client can't access it.")
    end
end
#

Client-side (inside StarterGui.LocalScript):

#
serverToClient.deleteFXforPlr.OnClientEvent:Connect(function(sound)
    if sound and sound:IsA("Sound") then
        sound:Destroy()
    else
        warn("Received nil or invalid sound")
    end
end)
minor iris
#
serverToClient.deleteFXforPlr:FireClient(plr, sound:GetFullName())
modest tundraBOT
#

studio** You are now Level 6! **studio

mystic eagle
#
local sound = Instance.new("Part")
        sound.CanCollide = false
        sound.CanQuery = false
        sound.CanTouch = false
        sound.CFrame = CFrame.new(pos)
        sound.Transparency = 1
        newSFX.Parent = sound
        sound.Parent = game.Workspace
        
        if delForPlr then serverToClient.deleteFXforPlr:FireClient(plr,sound) end
minor iris
#
sound:GetFullName() returns a string path, like:
"Workspace.GunshotEffects.Gunshot1"
#
serverToClient.deleteFXforPlr.OnClientEvent:Connect(function(soundPath)
    local success, sound = pcall(function()
        return game:GetService("Workspace"):FindFirstChild(soundPath, true)
    end)
    if success and sound and sound:IsA("Sound") then
        sound:Destroy()
    end
end)
#

So try now

#
local fxPart = Instance.new("Part")
fxPart.CanCollide = false
fxPart.CanQuery = false
fxPart.CanTouch = false
fxPart.CFrame = CFrame.new(pos)
fxPart.Transparency = 1
newSFX.Parent = fxPart
fxPart.Parent = workspace

if delForPlr then
    serverToClient.deleteFXforPlr:FireClient(plr, fxPart)
end
mystic eagle
#

your speed is incredible, thanks

#

now it's printing the route

#

but it's not deleting the sound

minor iris
#

You’re welcome. Open the Output window and paste the errors here for me

mystic eagle
#

there are no errors

minor iris
#

mmm

#

give me a while for analyze the problem

#

I'll give you the first common reason and how to fix it

#

# 1. Sound is not the same instance or not accessible on client
**- If you send a Sound instance from the server to client but it’s inside a Part or container not replicated or created on client, the client won’t see it or receive it properly.

  • You should send the container (e.g., the Part holding the sound), or better, send an ID or path and have the client find or create the sound themselves.**
#

now, I'll code a script can solve the problem