I was spended like 20 minutes to search for an answer, but result didn't appear. You can see EXAMPLE code, that means i dont use it in game.
--Client script-- remote = game.ReplicatedStorage:WaitForChild("RemoteEvent") rng = math.random(0,100) --Defining variable remote:FireServer(rng) --Firing this with variable --Server script-- remote = game.ReplicatedStorage:WaitForChild("RemoteEvent") function Print() print(rng) --Using that variable, also, there saying that this is unknown global end remote.OnServerEvent:Connect(Print) --Connecting script
If you try to run this code, you will get "nil". I hope you understand my issue.
you can pass it along as a parameter, for example:
local script:
game.ReplicatedStorage.exampleRemoteEvent:FireServer(exampleVariable)
server script:
game.ReplicatedStorage.exampleRemoteEvent.OnServerEvent:Connect(function(exampleVariable) -- your code here end)
That's only because you're not defining a parameter named rng
within the function. FireServer()
, the function you're trying to call, passes (but does not require) a minimum of one value:
In a sense, when you're doing this:
remote:FireServer(rng)
OnServerEvent
will receive:
function Print(player, rng) -- code end
You haven't defined any variables in your function, so rng
is nil.