Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUi tablet help?

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)

2 comments

0

Is there an output?

0

What do you mean

2 answers

✓ Accepted answer
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.

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 !

1 comment

0

I am

This discussion is preserved as it was. New answers, comments, and votes are closed.