How do I get a player's client to ask if another player's client is viewing something? For an example, I am making a game with a slenderman character, and I want players to be able to hallucinate, or basically have one or a few people be able to see slenderman at a time, while others see completely nothing. This will be done with having the server model invisible, but the client model will be completely visible to specific players.
I want the person playing as slenderman to know whether or not people are viewing him as visible or not from their client's side. There will be a popup gui that tells the player whether or not slender is visible from a client perspective (since the server model is most likely already invisible, just making sure the client side is visible or not). How would I tet that information?
Would I get the client to FireServer/Invoke to the server script, which has a local script inside of it that gets sent into that player's PlayerGui, and retrieves that information back to slenderman somehow.
You'd want to handle all of this on the server and send the necessary information to the clients as needed.
In a server script,
local watchingSlender = {} for i, v in pairs(game.Players:GetChildren()) do --[[ adds all players into watchingSlender. You want to make sure to remove them when they leave and add new players once they join.--]] watchingSlender[v.Name] = false end local function players_watching_slender() local watching = {} for i, v in pairs(watchingSlender) do if v then table.insert(watching, i) end end return watching end local function set_is_watching(player_name) watchingSlender[player_name] = true --use a remote event here to set slenderman to be visible for the given client end
You'd follow something similar to this. Every time that a new user can or can't see slender man you'd want to call players_watching_slender and then send that information to slender man via a remote event. On the client side you'd simply put these player names into a table and use that for the rest of your code.