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

How to get the user id of the player that fired an event?

How would I get the user id of the player that fired a remote event? I tried this code but it didn't work:

local item = script.Parent
local tool = game.ReplicatedStorage.WoodenSword
local clonedTool = tool:Clone()
local id = LocalPlayer.UserId -- Local player didn't work
item.MouseButton1Click:connect(function()
	game.ReplicatedStorage.RemoteEvent1:FireSrver()
	
	
	
	
end)


1 answer

✓ Accepted answer

Well you have not defined player, here let me help you.

local Player = game.Players.LocalPlayer -- gets running client
local UserID = Player.UserId

print(UserID)

Also, I've noticed a spelling mistake on line 06. Change FireSrver() to FireServer()

game.ReplicatedStorage.RemoteEvent1:FireServer()

If you are wanting to get UserId from server, it's a lot easier thank you think.

Upon a remote being fired, a parameter of player is automatically sent over.

game.ReplicatedStorage.RemoteEvent1.OnServerEvent:Connect(function(Player)
	print(Player.UserId)
end)

2 comments

0

And assuming you want the UserId to server, when firing a RemoteEvent, player is automatically fired over as a parameter. So you could automatically get UserId from the server.

0

Thank you so much! I have been looking everywhere for this! Thanks!

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