✓ Accepted answer
Decided to answer this because the last answer was unclear and didn't even put the real directory of the GUI...
On line 2 you put:
local GUI = game.StarterGui.ScreenGui
This is technically right, however it's not the actual player's Gui. The StarterGui service contains everything that is cloned into a thing called PlayerGui inside the player. The PlayerGui is what the player sees, not the StarterGui. So you were changing the Gui that is cloned into the player, meaning if you reset after you selected the tool it would have probably changed it on your new Gui.
We have to find the player's PlayerGui, and since we are uising a local script we can do game.Players.LocalPlayer and it will get the local player without needing the name. Then we will get PlayerGui which is a child of the player, and then finally your Gui called ScreenGui.
local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ScreenGui")
Final Script:
local Potion = script.Parent
local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ScreenGui")
local function Selected()
local TxtBox = Instance.new("TextBox")
TxtBox.Parent = GUI
TxtBox.Position = UDim2.new(0.5,0,0.5,0)
TxtBox.Size = UDim2.new(0.5,0,0.5,0)
TxtBox.BackgroundColor3 = Color3.new(0,0,0)
print("1")
end
local function Deselected()
local TxtBox = GUI:WaitForChild("TextBox")
TxtBox:Destroy()
print("2")
end
Potion.Equipped:Connect(Selected)
Potion.Unequipped:Connect(Deselected)
In addition I've included changes to your script to make it all up to date. :connect is deprecated for :Connect and Instance's Parent argument is deprecated. Commented at the end of the lines I changed.
8 comments
the :connect is not problem, problem is the GUI you need to edit GUI in PlayerGui.
oh :/
Edited
You forgot to found the GUI.
So why does his script not work? Please explain why it is not working not just posting a working script itself.
are you by chance using this in a server script? Server Scripts cannot access the PlayerGui
its in starterpack inside a tool
if this has no Handle then turn off requirehandle