#Question about Remote Events

38 messages · Page 1 of 1 (latest)

forest tapir
#

Let's say I want the server to show a GUI for all players, I could use a remote event with .OnClientEvent:Connect(function()) to make a GUI visible for all players. But what if, I want to make so the GUI will be visible for the player only if they meet a requirement (ex: having "a" in their name). How do I check each player's name inside the .OnClientEvent function?

novel burrow
#

One message removed from a suspended account.

deft compass
#

localscripts run on a player's computer

#

so each player has their own localscripts

#

if the code is inside a local script you can use Players.LocalPlayer to get the player that is running the script

forest tapir
deft compass
forest tapir
#

client

deft compass
#

it might be vulnerable to exploiters if you do it on the client

novel burrow
#

One message removed from a suspended account.

#

One message removed from a suspended account.

forest tapir
#

:FireAllClients() sends a remote for all players right?

novel burrow
#

One message removed from a suspended account.

forest tapir
#

How do I make so I know which player it is currently itering

novel burrow
#

One message removed from a suspended account.

forest tapir
#

Like

    print(player.Name)```
novel burrow
#

One message removed from a suspended account.

#

One message removed from a suspended account.

forest tapir
novel burrow
#

One message removed from a suspended account.

#

One message removed from a suspended account.

forest tapir
deft compass
#

and do the validation in the loop

forest tapir
#

Exemple:

There is a :FireAllClients() that sends a remote to all players (let's say se have "Player1", "Player2" and "Player3"). When I handle that remote, so using .OnClientEvent, I would like to check if the player has "3" in their name, if so, then do something (a function) else do nothing

forest tapir
#

forgot about that 😅

#

thx!

forest tapir
static solar
#

id reccomend

#

-- (serversided)
local players = game.Players

local function displayUI(letter)
  for i, player in pairs(players:GetChildren()) do
    --loop thru name
    local playerString = player.Name:split("") --
    for i, v in pairs(playerString) do
      if v == letter then
          local UI = player.PlayerGUI.ScreenGUI.Frame.Visible = true -- (example)
        print("player : " .. player.Name .. " had their UI turned on")
      end
    end
  end
end

local remote = ...
local letter = "a"
remote.OnServerEvent:Connect(function()
  displayUI(letter)
end

i dont really remember how :split works

#

string.split

#

youll have to look that up but this should be the basic premise of it