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

how to find the player who clicked a buttons' user id?

Asked by
Galicate 106
7 years ago

ok so title is confusing. How would I find the user id of a player that clicked a gui button?

function Click(player) 
    print("Terminal Works")
    if player.UserId == 293872889 then
    script.Parent.Parent.Parent.Access:Play()
    wait(1)
    script.Parent.Parent.Parent.Options.Visible = true
    script.Parent.Parent.Parent.LoginFrame.Visible = false
    else
        print("User failed to access a terminal.")
        script.Parent.Parent.Parent.Denied:Play()
        end
    end

script.Parent.MouseButton1Click:connect(Click)

2 answers

Log in to vote
1
Answered by
Jellyfosh 125
7 years ago

If this is in a gui you should be using a LocalScript, so you can just do:

local player = game:GetService("Players").LocalPlayer

Also, MouseButton1Click returns the players mouse, not the player.

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hope this helps :)

local player = game:GetService("Players").LocalPlayer

function Click() 
    print("Terminal Works")
    if player.UserId == 293872889 then
    script.Parent.Parent.Parent.Access:Play()
    wait(1)
    script.Parent.Parent.Parent.Options.Visible = true
    script.Parent.Parent.Parent.LoginFrame.Visible = false
    else
        print("User failed to access a terminal.")
        script.Parent.Parent.Parent.Denied:Play()
        end
    end

script.Parent.MouseButton1Click:connect(Click)

0
If you have any problems let me know. StoleYourClothes 105 — 6y

Answer this question