Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I get a players ID from their username?

Asked by 5 years 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 705 — 5y
0
you cannot just make up and create arguments for a function; they are predetermined. KDarren12 705 — 5y
0
It is not a click dectector, this is located in a GUI. DennisSense 23 — 5y
0
oh then still, it's a different argument KDarren12 705 — 5y

2 answers

Log in to vote
1
Answered by
Velsity 218 Moderation Voter
5 years ago
Edited 5 years 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 705 — 5y
0
It is. Velsity 218 — 5y
0
Thank you so much, it worked! DennisSense 23 — 5y
Ad
Log in to vote
0
Answered by 5 years 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 23 — 5y

Answer this question