Sending Server Information to Client Error

I’m attempting to send a folder located in serverstorage from the server to a client via a remote event.

Here are parts of the script:

--In the server
local Folder = game.ServerStorage.Folder
Event:FireAllClients("M", Folder)

--In the client
Event.OnClientEvent:Connect(function(event, folder)
  print(folder) -- it is nil
end)

I’m figuring that it’s because I can’t access it from the client since it’s part of the server, but I’m not entirely sure if that’s the case.

Ah!

Event.OnServerEvent:Connect(function(event, folder)

is your problem,
the romote event can only be called on clients using OnClientEvent.

oh whoops i mistyped that in my post but that’s not the case as you can see here

1 Like

it prints nil just for it to double check as well Screenshot by Lightshot

1 Like

Oh nevermind, I believe it’s because, when firing to clients the first variable has to be a player value.

--In the server
local Folder = game.ServerStorage.Folder
Event:FireAllClients(plr,"M", "Folder")

--In the client
Event.OnServerEvent:Connect(function(event, folder)
  print(folder) -- it is nil
end)

Try this.

:FireClient(plr, “M”, Folder) would be what you are attempting to say

:FireAllClients(“M”, Folder) is firing all clients

im looking to fire all clients in this case

The folder is parented to server storage which only the server can access.

thats what i assumed so unfortunately i guess im going to risk giving all the data to all clients, putting it in replicatedstorage

Yep unless you send the data as a table and let the client interpret it

smart move i might do that then

The first argument using OnServerEvent is Player.

yea ik i mistyped it here but its OnClientEvent in my script since i didnt copy paste

Try printing the string. Or use a Loop to get the folder objects.

You can’t access the ServerStorage in a LocalScript, it’s replicated across the server side

Put it in ReplicatedStorage instead:

--In the server
local Folder = game.ReplicatedStorage.Folder
Event:FireAllClients("M", Folder)

--In the client
Event.OnClientEvent:Connect(function(event, folder)
    print(event)
    print(folder)
end)

thats what i did as the fix but i think i might do what @0xzemqkaixlqpolwmzvn had said and put them into a table to keep it “encrypted” but im feeling pretty lazy rn so :man_shrugging:

:FireAllClients() only works on Server-Side.

thank you all for the help to the eventual fix @SimpingHour @0xzemqkaixlqpolwmzvn @Trixeller @JackscarIitt

1 Like

W h a t

He referenced the script as a server script when he called FireAllClients(), I’m not blind?