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

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

Asked by 5 years ago

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

01GroupID = 3713839
02Button = script.Parent.Screen.SurfaceGui.Frame.Button
03Button.MouseButton1Click:Connect(function(Clicked)
04    local Player = game.Players:GetPlayerFromCharacter(Clicked.Parent.Parent)
05    local ServerStorage = game.ServerStorage
06if Player:IsInGroup(GroupID) then
07    Button.Text = "Currently in use"
08    Button.TextSize = 55
09    end
10end)

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

2 answers

Log in to vote
0
Answered by 5 years ago

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:

01local groupId = 3713839
02local button = script.Parent.Screen.ClickDetector
03 
04button.MouseClick:(function(player)
05    local serverStorage = game:GetService("ServerStorage')
06 
07    if player:IsInGroup(groupId) then
08        button.Text = "Currently in use."
09        button.TextSize = 55
10    end
11end)
0
I don't want to since I'm using a gui. iiBuilder_Boy 27 — 5y
0
In that case, I'm not to sure what to do. namespace25 594 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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:

1player = game.Players.LocalPlayer

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

01GroupID = 3713839
02 
03--Function that runs when the button is clicked.
04script.Parent.MouseButton1Click:Connect(function()
05--References the player (you can only reference the player like this in a local script.)
06local Player = game.Players.LocalPlayer
07    --Checks if the player is in the group and changes the text if so.
08    if Player:IsInGroup(GroupID) then
09        script.Parent.Text = "Currently in use"
10        script.Parent.TextSize = 55
11    end
12end)
0
Doesn't work. And there is no output errors. iiBuilder_Boy 27 — 5y
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. Alexander_Ashford 231 — 5y

Answer this question