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.

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

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:

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)
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:

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)

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