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

Getting player from textbutton?

This is my code, I want to obtain the player that clicked the textbutton, but its not working. Help?

function Dialog(player)
	print("Ere")
	if player ~= nil then
		
		CreateDialog("Are You ok?",player)
		CreateDialog("Oh god, you're bleeding",player)
		CreateDialog("What was that?",player)
	end
	
end
script.Parent.TextButton.MouseButton1Click:connect(Dialog)

4 comments

0

Please expand this more I do not understand what you trying to say.

0

I want to obtain the player who clicked on the textbutton, by using an arguement (player) but it isn't working.

0

TextButton's do not return the player as an argument.

0

Is there a way to obtain the player?

1 answer

If this script is a local script, inside the PlayerGui/StarterGui, you can just get the player by doing this:

local player = game.Players.LocalPlayer

Here is an example in your given code:

local player = game.Players.LocalPlayer

function Dialog()
    print("Ere")
    if player ~= nil then

        CreateDialog("Are You ok?",player)
        CreateDialog("Oh god, you're bleeding",player)
        CreateDialog("What was that?",player)
    end

end
script.Parent.TextButton.MouseButton1Click:connect()

Hope this helps, don't forget to accept the answer. It gives us both rep!

1 comment

0

It isn't what I'm looking for. I want to obtain the player who clicked on the text button by using an argument (player)

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