Hello, I would like to transfer a global table to my local script. Is there any way?
(SERVER SCRIPT)
1 | print (_G.tab [ 1 ] ) --> player has got 5 points. |
(LOCAL SCRIPT)
1 | print (_G.tab [ 1 ] ) --> nil |
I tried to transfer the data via a StringValue, and Changed event, but it hardly works. (Bad timing)
Use RemoteEvents, they are extremely helpful in this situations.
LocalScript inside player's PlayerGui
1 | event = game.ReplicatedStorage:WaitForChild( "Stream" ) |
2 | event.OnClientEvent:connect( function (msg) |
3 | print (msg) |
4 | end ) |
Script inside ServerScriptService
1 | event = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
2 | event.Name = "Stream" |
3 | while wait( 5 ) do |
4 | event:FireAllClients( "Player has got 5 points" ) |
5 | end |
You can also fire the event for only a client using FireClient(Player player, arguments)