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

How to give a UI to certain players through server events???

Asked by 3 years ago

I've been up for a while trying to figure out how to give certain people an admin UI through a server event by being added or deleted from Player UIs. Please help me find out what's wrong here, there isn't an error in studio but in 2 player test servers it says that the UI isn't part of player.

Local Script:

local TextBox = script.Parent.Parent:FindFirstChild("PlayerSelectGui")
local GiveUIEvent = game.ReplicatedStorage.AdminFolder.AdminEvents:WaitForChild("GiveUI")
local InsertedPlayer = TextBox.Text
local LocalPlayer = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
    InsertedPlayer = TextBox.Text
    print(InsertedPlayer)
    GiveUIEvent:FireServer(InsertedPlayer)
end)

Server Script:

local Players = game:GetService("Players")
local AdminEvents = game.ReplicatedStorage.AdminFolder.AdminEvents
local AdminGui = game.ReplicatedStorage.AdminFolder:WaitForChild("AdminGUI")


AdminEvents.GiveUI.OnServerEvent:Connect(function(plr, InsertedPlayer)
    plr = InsertedPlayer
    if (game.workspace:FindFirstChild(plr) ~= nil) then
        print("plr Found")
        if (game.workspace[plr]:FindFirstChild("Humanoid") ~= nil) then
            print("plr Humanoid Found")
            if not (game.Players[plr].PlayerGui.AdminPanel) then
                local AdminPanel = AdminGui:Clone()
                AdminPanel.Name = "AdminPanel"
                AdminPanel.Parent = plr.PlayerGui
                AdminPanel.Enabled = true
            else
                print("Player has admin")
            end
        end
    end
end)

Answer this question