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

How to check username of player who clicked textbutton?

Ok so I have this script that when you click it, it says "Taken by !"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?

3 comments

0

Remote events

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)

0

Place a separate TextButton in every player's PlayerGui

1 answer

✓ Accepted answer

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)

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