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

How would I make sure the person who clicked it is in the group and change text with a TextButton?

Basically I asked a previous question which I thought when it was answered would answer the problem to what I'm trying to do.

GroupID = 3713839
Button = script.Parent.Screen.SurfaceGui.Frame.Button
Button.MouseButton1Click:Connect(function(Clicked)
	local Player = game.Players:GetPlayerFromCharacter(Clicked.Parent.Parent)
    local ServerStorage = game.ServerStorage
if Player:IsInGroup(GroupID) then
    Button.Text = "Currently in use"
    Button.TextSize = 55
	end
end)

I don't know what to do. The group Id is correct I just can't get the player.

2 answers

Everything is correct except for the fact that you're trying to get the player from the nothing. There is no argument from MouseButton1Click. If you do insert a click detector, however, you can do this:

local groupId = 3713839
local button = script.Parent.Screen.ClickDetector

button.MouseClick:(function(player)
	local serverStorage = game:GetService("ServerStorage')

	if player:IsInGroup(groupId) then
		button.Text = "Currently in use."
		button.TextSize = 55
	end
end)

2 comments

0

I don't want to since I'm using a gui.

0

In that case, I'm not to sure what to do.

The first question you asked was about when you touch a part. If your doing it via a GUI then you do not need to use GetPlayerFromCharacter as you are using a local script for a GUI.

A local script already knows who the player is. Therefore you can reference the player as:

player = game.Players.LocalPlayer

Therefore you can adjust your script as such (put the local script in the button):

GroupID = 3713839

--Function that runs when the button is clicked.
script.Parent.MouseButton1Click:Connect(function()
--References the player (you can only reference the player like this in a local script.)
local Player = game.Players.LocalPlayer
	--Checks if the player is in the group and changes the text if so.
	if Player:IsInGroup(GroupID) then
		script.Parent.Text = "Currently in use"
		script.Parent.TextSize = 55
	end
end)

2 comments

0

Doesn't work. And there is no output errors.

0

Ah I see why. I didn’t define what Button was. Make Button script.Parent instead ie script.Parent.Text. I updated my script.

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