Transfer data through remote events

I want to know how to transfer data through remote events. I’ve seen this in games before where they only have 1 remote event that handles many things by transferring data to the server.

I don’t know how to pick up the data on the server side, though. Any help?

local event = game.ReplicatedStorage.Event1

-- random script where it checks for a keybind

event:FireServer("ability", something else idk) -- this line here, how would I pick up "ability" on the server side and then do something if the event sends "ability" ?
3 Likes

Whatever you send inside the brackets of FireServer() will be the parameters on the RemoteEvent listening for it.

Event.OnServerEvent:Connect(function(Player, Args)
   print(Args)
end)
7 Likes

so i would have something like

Event.OnServerEvent:Connect(function(Player, ability)
??

In your case, that will be correct. The ability will be a string if you send it as “Ability”.
You can also send instances/objects as long as they exist on the server, client-created instances/objects will return nil if sent.

1 Like

thank you so much! (char limit)

1 Like

when i try to send it as “Ability” and put “Ability” in the server script parameters, it gives me an error

What’s your current code?
Helps with debugging if you can show it.

1 Like

server script:

game.ReplicatedStorage.SetupEvents.GenderSelect.OnServerEvent:Connect(function(player, Female, Male)
	if Male then
		print("male")
	elseif Female then
		print("female")
	end
end)

local scripts:


script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SetupEvents.GenderSelect:FireServer("Male")
end)
male

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SetupEvents.GenderSelect:FireServer("Female")
end)

it always prints Female for some reason

You only need 1 parameter, it will either be female or male depending on what you send, ex “Female”, “Male”.

1 Like

so would i make 2 functions in the serverscript, one with female and one with male?

i just tried 2 functions and it prints both no matter which one i click

I think you can understand it the way I made it now.

local RemoteEvent = game:GetService('ReplicatedStorage').RemoteEvent


local function ServerEvent(Player, FemaleOrMale)
    if (FemaleOrMale == 'Female') then
        print("It's a female!")
        
    elseif (FemaleOrMale == 'Male') then
        print("It's a male!")
    end
end


RemoteEvent.OnServerEvent:Connect(ServerEvent)
2 Likes

would this affect the local scripts?

No, the local script is just sending a request to the server, it doesn’t affect the script at all.

1 Like

so i still send it as “female” and “male” in the local scripts?

thank you, it works! :smiley: (characters)()))

1 Like

Yup! Just send it like this:

Event:FireServer('Male')
Event:FireServer('Female')
1 Like