Currently I’m trying to make a system to were if you touch a button a gui will appear. (I’ve done that already) But the trouble I’m having is that I want it to show only if you are a certain group rank and only that rank can see it.
Button Script:
local button = script.Parent
local clickdetector = button.ClickDetector
function onMouseClick(player)
local playerUI = player:FindFirstChild("PlayerGui")
playerUI.ButtonGui.Frame.Visible = true
end
clickdetector.MouseClick:connect(onMouseClick)
Tween script (Local script):
local button = workspace.Button
local object = script.Parent
local clickdetector = workspace.Button.ClickDetector
function onMouseClick(player)
object.AnchorPoint = Vector2.new(0, 0)
object.Position = UDim2.new(1, 0, 0.905, 0)
wait(0.5)
object:TweenPosition(UDim2.new(0.837, 0, 0.905, 0))
end
clickdetector.MouseClick:connect(onMouseClick)
In other words, I’m trying to make it so that a certain group rank will be able to see a gui when another player presses a button, but that player won’t be able to see the gui and only the person that has the certain group rank will be able to see it.
Well the thing is when I do game.Players.PlayerAdded:Connect(function(Player) it will show an error telling me that onMouseClick needs to be changed to local?
I don’t know what your script looks like but you should probably put the playeradded event and clone it before and just make it so you can’t see it until you press the button.
It seems I’ve got something right but the first onMouseClick still seems to be an error…
game.Players.PlayerAdded:Connect(function(Player)
local button = script.Parent
local clickdetector = button.ClickDetector
function onMouseClick(player)
local playerUI = player:FindFirstChild("PlayerGui")
if Player:GetRankInGroup(6201590) == 255 then
playerUI.ButtonGui.Frame.Visible = true
else
playerUI.ButtonGui.Frame.Visible = false
clickdetector.MouseClick:connect(onMouseClick)
end
end
end)
You can’t run the function in the actual function, you need to call it outside it:
function onMouseClick(player)
local playerUI = player:FindFirstChild("PlayerGui")
if Player:GetRankInGroup(6201590) == 255 then
playerUI.ButtonGui.Frame.Visible = true
else
playerUI.ButtonGui.Frame.Visible = false
end
end
end)
clickdetector.MouseClick:Connect(onMouseClick)