How can I pass a global variable from ServerScript to LocalScript? Can someone also provide an example I can follow? Many Thanks!
You could make a RemoteEvent about this, but you could figure out the rest yourself since it isnt that hard
lets say there is a RemoteEvent in replicatedstorage right now, named TestRemote
this is a serverscript, in serverscriptservice for example
game:GetService("Players").PlayerAdded:Connect(function(player) local x = 0 x = 1 x = 2 x = 3 x = 4 x = 5 game:GetService("ReplicatedStorage").TestRemote:FireClient(player, x) x = 6 x = 7 end)
and here is a localscript:
game:GetService("ReplicatedStorage").TestRemote.OnClientEvent:Connect(function(x) -- Warning, do not put player parameter here, it wont work because there is no player parameter in OnClientEvent, i made that mistake like 3 times lol print(x) -- 5 end)
Of course, you can transfer Instances too,
script:
game:GetService("Players").PlayerAdded:Connect(function(player) game:GetService("ReplicatedStorage").TestRemote:FireClient(player, game.Workspace.Part) end)
localscript:
game:GetService("ReplicatedStorage").TestRemote.OnClientEvent:Connect(function(part) print(part.Name) -- Part end)
oh by the way, if your question isnt like what i answered, or you can explain a little more details on the script (you can delete some parts you dont want to show, some people do it)