Sorry if this is confusing, but if I have a local script in StarterGui, and I get info from a remote function, lets say its called Name. How could I find and use name anywhere in the script, like above it and not in the function.
1 Like
you could have a undefined variable at the top of the script and define it once the event is called
local nameVariable
event.OnClientEvent:Connect(function(name)
nameVariable = name
end)
while task.wait() do
if nameVariable then
print(nameVariable)
end
end
1 Like
You can also do this to check if it isn’t nil and has a certain value:
local nameVariable -- nil by default
event.OnClientEvent:Connect(function(name)
nameVariable = name -- sets value to name
end)
while task.wait() do -- loops always
-- if the name isnt nil and is equal to 123 then print name
if nameVariable and nameVariable == "123" then
print(nameVariable)
end
end