I have been having a lot of trouble getting a variable in my local script to my server script from teleport data is there any way to do this?
COMMUNITY QUESTION
How can I take a variable from a localscript and put it into a server script?
2 answers
The best way to do this is to use bindable events,
So say your workspace looked something like this
Workspace
-Script1
-Script2
-BindableEvent
What we would want to do to transfer a variable from Script1 to Script2 which has a remove event,
In Script1 our code would look something like this
WaitForVariable = game.Workspace:WaitForChild("Script2") --Here we are waiting for Script2 to exist in the workspace.
myVariable = 123 --Here we are defining the variable
game.Workspace.Script2.BindableEvent.Fire(myVariable) --Here we are activating the event
In Script2 We would need to get that data that we just sent over,
function DataTransfer(Data)
myVariable = Data
end
script.Event.Event:Connect(DataTransfer)
Now if we were to print myVariable it should print 123.
Or you can make Remote events
Examples:
Local Script:
workspace.ChildAdded:Connect(function(add)
script.Parent.Remotes.Child.Added:FireServer(add)
end)
Server Script:
script.Parent.Child.Added.OnServerEvent:Connect(function(add)
if add then
if add:IsA("Part") then
add.Shape = "Ball"
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
remote events
Remote events and remote functions.
You could also use ModuleScripts, but RemoteEvents are preferred for data transfer.
Could you post an example on how to use remote events to do this