So here's how you would send data from a local script to a server:
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
TextBox:GetPropertyChangedSignal("Text"):Connect(fuction()
event:FireServer(TextBox)
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local function OnEvent(player, TextBox)
print(TextBox.Text)
end
event.OnServerEvent:Connect(OnEvent)
event.OnServerEvent:Connect(function(player, TextBox)
print(TextBox.Text)
end)
So anytime you are dealing with Replicated Storage events you always want to have in your script the following:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NameOfEventCanBeAnything = game.ReplicatedStorage:WaitForChild("WhateverYouNamedTheRemoteEventInYourReplicatedStorage")
An important note is you don't have to use WaitForChild. But it's whatever.
So after you included those in your local script you need to fire variables to the server like you did so:
NameOfEventCanBeAnything:FireServer(TextBox)
This actually passes two variables, player and TextBox. When you fire to the server player is always passed as the first parameter.
Now in the server you always need to have these:
local function TheFunctionYouWantToCall (player, VariableYouPassedIn)
WhateverYouNamedYourEventCanBeAnything.OnServerEvent:Connect(TheFunctionYouWantToCall)
The OnServerEvent:Connect listens for WhateverYouNamedYourEventCanBeAnything to recieve values from the local script and if it does it calls the function and passes those values into it.
So in your case the VariableYouPassedIn was TextBox. You don't have to put the name of the TextBox, it can be anything as long as it's in the right spot it becomes TextBox if that makes sense.
So what I mean is if you said FireServer(TextBox),
the function in your server can be local function WhateverYouWantToCallIit(player, BLAH)
and BLAH will be TextBox.
1 comment
It gives "TextBox", I typed in (player,TextBox), print(TextBox.Text). how to manage datasent? Do i have to type something in local script?