New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
1

# How do I get a players ID from their username?

Asked by 11 days ago

I am using a regular server script, which it can not get the users playerID.

script.Parent.MouseButton1Click:Connect(function(Player)
local playerId = Player.UserId
script.Parent.Parent.No1.Value:WaitForChild('Eng').P1.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P1.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P2.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P2.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P3.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P3.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P4.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P4.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P5.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P5.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P6.Disabled = false
script.Parent.Parent.Confirm.BackgroundColor3 = Color3.new(0, 255, 0)


In the developer console it was saying "attempt to index local 'Player' (a nil value)

0
why are you trying to find a Player inside of a ClickDetector...? KDarren12 690 — 11d
0
you cannot just make up and create arguments for a function; they are predetermined. KDarren12 690 — 11d
0
It is not a click dectector, this is located in a GUI. DennisSense 16 — 11d
0
oh then still, it's a different argument KDarren12 690 — 11d

1
Velsity 183
11 days ago
Edited 11 days ago
local player = game.Players.LocalPlayer
local ID = player.UserId

script.Parent.MouseButton1Click:Connect(function()
print(ID)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P1.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P1.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P2.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P2.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P3.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P3.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P4.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P4.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P5.Disabled = false
wait(2)
script.Parent.Parent.No1.Value:WaitForChild('Eng').P5.Disabled = true
script.Parent.Parent.No1.Value:WaitForChild('Eng').P6.Disabled = false
script.Parent.Parent.Confirm.BackgroundColor3 = Color3.new(0, 255, 0)



If I understand you correctly, you wanna know the ID of a player.

This is also a localscript, if you wish to do anything on the server, use a remoteevent.

What I did was refer to the ID of the player, which is the localplayer. And print it everytime they click the GUI

Also, you can use GetUserIdFromNameAsync if you really wanna do it from the server side, but it's gonna be harder.

0
ur formatting was not correct; write code inside of the ~'s. KDarren12 690 — 11d
0
It is. Velsity 183 — 11d
0
Thank you so much, it worked! DennisSense 16 — 11d
0
Answered by 11 days ago

You are using a gui. Guis do not have any way of getting the player as they are supposed to be manage by LocalScripts, which can access game.Players.LocalPlayer. Use a remote event.

LocalScript (Parented to gui button):

script.Parent.MouseButton1Click:Connect(function()
local remoteEvent = game.ReplicatedStorage.RemoteEvent -- Make a remote event and reference it here
remoteEvent:FireServer(script.Parent)
end)


ServerScript (Parented to gui button):

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, gui) -- Reference same remote event
local playerId = player.UserId
-- Type the rest of the code here (replace every script.Parent with gui)
end)

0
Thank you so much for trying to help! DennisSense 16 — 11d