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

Best way to script a group and rank only gui?

Asked by 5 years ago

I am trying to make a GUI that is only available for people who are in a certain group, And are above the rank of 200 in that group. Anyone below the rank 200 doesn't get the GUI. I can't seem to get the below script working, Any help would be appreciated and if there is an easier way could you please show me.

local config = script.Parent.Configuration

script.Parent.Touched:connect(function(part)
    if part.Parent and game:GetService('Players'):GetPlayerFromCharacter(part.Parent) then
        local player = game:GetService('Players'):GetPlayerFromCharacter(part.Parent)
        if player:GetRankInGroup(config.GroupId.Value) >= config.RankId.Value then
            game.StarterGui.MusicP.Enabled = true
        end
    end
end)

2 answers

Log in to vote
1
Answered by 5 years ago

The problem lies in the fact that you wrongly assume that the StarterGui is where the player's GUI will be. When you modify contents from the StarterGui, the changes you made will not show until a player resets.

StarterGui vs PlayerGui

The StarterGui is basically what PlayerGui clones out of when you first join the game and when you respawn (so the real GUI is in the PlayerGui, child of the Player object). In order to fix this, you should look for the GUI inside of PlayerGui. But there is a problem. The server cannot see the descendants of PlayerGui, unless those descendants were placed by the server itself. You can either clone the GUI from the server or use RemoteEvents. In this example I will use a RemoteEvent.

local remote = Instance.new("RemoteEvent")
remote.Name = "ShowGui" -- just an example 
remote.Parent = game:GetService("ReplicatedStorage")
local config = script.Parent.Configuration
local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(part)
    -- connect is deprecated, so use Connect!
    local client = Players:GetPlayerFromCharacter(part.Parent)

    if client then
        remote:FireClient(client)
    end
end)

From the local script:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("ShowGui")
local client = game:GetService("Players").LocalPlayer

remote.OnClientEvent:Connect(function()
    -- Find the gui in PlayerGui.
end)
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

game.Players.ChildAdded:connect(function(player) if player:IsInGroup(0000) if player.PlayerGui:findFirstChild("GroupGui") == nil then

        local newGui = script.GroupGui:clone() 
        newGui.Parent = player.PlayerGui
    end
end
player.Changed:connect(function(prop) .
    if prop == "Character" then
        if player:IsInGroup(0000) then 
            if player.PlayerGui:findFirstChild("GroupGui") == nil then
                local newGui = script.GroupGui:clone() 
                newGui.Parent = player.PlayerGui
            end
        end
    end
end)

end)

0
None of these seem to work for me. samual123456 2 — 5y

Answer this question