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

How to check username of player who clicked textbutton?

Asked by
Faazo 84
6 years ago
Edited 6 years ago

Ok so I have this script that when you click it, it says "Taken by <name of the player who clicked>!"but it says click is a nil value. This usually works with touched events and clickedetector but its not working with gui clicks, so I'm looking for a way to check the name of the player who clicked it. Here is my script.

local function OnClick(Click)
    script.Parent.TakenBy.Text = ("Taken by"..(Click.Parent.Name).."!")
end

script.Parent.MouseButton1Click:Connect(OnClick)

I have a click parameter in my function, yet the output says click is a nil value. I also can't write "LocalPlayer.Name" because that only works in a local script, and I need the whole server to see this change. A localscript of course can't change it for the entire server because filtering is enabled. Does anyone have any ideas on how to solve this?

0
Remote events User#20388 0 — 6y
0
(MouseButton1Click doesn't have any arguments that tell who clicked is, because FE that isn't required either, for the client, only 1 person exists) User#20388 0 — 6y
0
Place a separate TextButton in every player's PlayerGui Amiaa16 3227 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Errors:

The GuiButton.MouseButton1Click event has no parameters.

In line 2, you wrapped your string in brackets, remove them since they are math exclusive, and arithmetic cannot be performed on a string. And in general they are just plain redundant.

I will rewrite your script, with a RemoteEvent.

-- RemoteEvent coding, server side.

game.Workspace.RemoteEvent.OnServerEvent:Connect(function(plr)
    local m = Instance.new("Message", game.Workspace)

    m.Text = "Taken by: "..plr.Name.."!"
        --See, no brackets? I would get an error if used.

    wait(5)
    m:Destroy() 
end)

Client-side code.

script.Parent.MouseButton1Click:Connect(function()

    game.Workspace.RemoteEvent:FireServer()

end)
Ad

Answer this question