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)
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.
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 RemoteEvent
s. 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)
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)