Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to use a server script to identify a specific player?

For a game I'm making when a player joins it creates a folder of RemoteEvents so that the player can fire them to do specific things without affecting the whole server (so if a player pushes a key it fires a RE that then gets picked up by a ServerScript in the player's character to spawn the ammo)

The problem is I have a SS that's in a BillboardGui in game.Workspace and I want to make it so when the player pushes a key it clones it to their PlayerGui and adornees it to the brick so only they can see the BBG but the problem is that I've tried using RemoteFunctions to do this (https://scriptinghelpers.org/questions/112137/remotefunction-only-invoking-one-script-at-a-time) and it works but only does it for one, there are multiple copies of this on the map but only one script gets activated by the RemoteFunction invoking the server, this is the only way I can think of to get the Player's name

I wanted to see if there's a way to make the ServerScript somehow get the name of the player who fires a certain RemoteEvent so I can just use that to identify the player and access their RemoteEvents folder

1 comment

1

Remote events passed to the server come with their usernames as default first parameter. You can store the usernames in a table after they joined though if that solves whatever you are trying to do

1 answer

Paragraph 1: Don't bother creating a new folder of events for each player, events send "player" as the default 1st arg (for client to server click here)

Paragraph 2: Why not just have the Gui in the StarterGui and just enable it when you want it? That way you dont ahve to clone anything at all, just toggle it on/off.

Paragraph 3: Following script pulled from here)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("remotes")[remote name]

local function onEvent(player, stat_name) --function to run on trigger
	return(DS:GetStat(player, stat_name))
end

remote.OnServerEvent = onEvent --binds onInvoke to server event

Note that the connected function (lines 4-7) will receive the Player who fired the event as its first parameter (player), along with any additional parameters passed from the FireServer() call.

Best of luck, let me know if this helps!

2 comments

0

WaitForChild is not required in this content.

0

Thank you, I've also just realised that if WaitForChild is to be used it should also have a time limit. I had pretty much just copied this from my adaptation of the tutorial for a RemoteFunction :)

This discussion is preserved as it was. New answers, comments, and votes are closed.