Whats wrong with this

im trying to get it so that the script shows a button stored in serverstorage, i found a way but it only works once, once the player dies it dissapears.

i tried this but it wont work either

local Players = game:GetService("Players")
local GroupId = 32577708 
local function ShowMenu(char)
	game:GetService("ServerStorage"):WaitForChild("AdminButton"):Clone().Parent = Players:GetPlayerFromCharacter(char).PlayerGui.ScreenGui
end
Players.PlayerAdded:Connect(function(Player)
	print(Player:GetRoleInGroup(GroupId))
	if(Player:GetRoleInGroup(GroupId) == "Admin" or Player:GetRoleInGroup(GroupId) == "Owner") then
		Player.CharacterAdded:Connect(ShowMenu)
	end
end)

edit: what i mean by it does not work is that it literally does not show anything up.

2 Likes

You should switch the order in which you connect the events. First use .CharacterAdded then check if they have the appropriate role. The delay in time when the server checks if they are the proper role doesn’t properly connect the event on startup.

1 Like

Are you trying to make a non-visible GUI become visible ? You might be missing the part in the script that makes the GUI become visible.

no, just cloning it into the players GUI

1 Like

huh, could you reword it im kinda confused?

1 Like

Try making it so that it becomes visible instead of cloning it. You can then put the GUI in StarterGUI instead of ServerStorage. You’ll have to make sure the GUI’s visibility is disabled by default, though.

Got it, ill try that tommorow as its 2 am for me right now.
but what if some exploiter just makes it visible and messes with the admin panel in my game

1 Like

I don’t really know how you’ll deal with that, I’m not much of a scripter myself. Unless your game is popular, that shouldn’t happen, so you shouldn’t have much to worry about.

That’s why you add server side checks to prevent this.
Edit: any errors?

1 Like

That sounds like a good solution.

1 Like

no errors, also the script is in serverscriptservice btw

1 Like
Players.PlayerAdded:Connect(function(Player)
 
 Player.CharacterAdded:Connect(function(Char)
    if (Player:GetRoleInGroup(GroupId) == "Admin" or Player:GetRoleInGroup(GroupId) == "Owner") then
      ShowMenu(Char)
    end
  end)

end)

That would work but it would be better if you passed player directly. Additionally, add WaitForChild when getting the player gui because it takes a second to load I think.

1 Like

I fixed it, heres the solution

local Players = game:GetService("Players")
local GroupId = 32577708 
local function ShowMenu(char)
	game:GetService("ServerStorage"):WaitForChild("AdminButton"):Clone().Parent = Players:GetPlayerFromCharacter(char):WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
end
Players.PlayerAdded:Connect(function(Player)

	Player.CharacterAdded:Connect(function(Char)
		if (Player:GetRoleInGroup(GroupId) == "Admin" or Player:GetRoleInGroup(GroupId) == "Owner") then
			ShowMenu(Char)
		end
	end)

end)

nevermind, it only works when u die once. if you die again after that it does not appear

Try this:

local Players = game:GetService("Players")
local GroupId = 32577708 
local function ShowMenu(Player)
	local button = game:GetService("ServerStorage"):WaitForChild("AdminButton"):Clone()
	button.Parent = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
	button.Parent.ResetOnSpawn = false
end
Players.PlayerAdded:Connect(function(Player)
	if (Player:GetRoleInGroup(GroupId) == "Admin" or Player:GetRoleInGroup(GroupId) == "Owner") then
		ShowMenu(Player)
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.