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

GUi tablet help?

Asked by 9 years ago

So I am making a gui tablet but I beleive there is a problem with this script,the gui won't show up when I equip it,it worked in solo mode but not public.

local gui = script.Parent.TabletGui:Clone()

function Equip()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
end

function Unequip()
    gui.Parent = nil
end

script.Parent.Equipped:connect(Equip)
script.Parent.Unequipped:connect(Unequip)
0
Is there an output? bbissell 346 — 9y
0
What do you mean Ex_plore 62 — 9y

2 answers

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
9 years ago
local gui = script.Parent.TabletGui:Clone()
local plr = game.Players.LocalPlayer

function Equip()
    gui.Parent = plr:WaitForChild("PlayerGui")
end

function Unequip()
    if plr:WaitForChild("PlayerGui"):FindFirstChild("TabletGui") then
            plr.PlayerGui:FindFirstChild("TabletGui"):Destroy()
    end
end

script.Parent.Equipped:connect(Equip)
script.Parent.Unequipped:connect(Unequip)

Make sure this is a local script or this will not work.

Ad
Log in to vote
1
Answered by 9 years ago

Here is a simple fix for your script:

function Equip()
    local Player = game.Players.LocalPlayer
    local gui = script.Parent['TabletGui']
    if not UI and gui and Player and Player:FindFirstChild('PlayerGui') then
        UI = gui:Clone()
        UI.Parent = Player.PlayerGui
    end
end

function Unequip()
    if UI then
        UI:remove()
        UI = nil
    end
end

script.Parent.Equipped:connect(Equip)
script.Parent.Unequipped:connect(Unequip)
  • This expects that you are running this code in a Local Script !
0
I am Ex_plore 62 — 9y

Answer this question