Scripting Help With ScreenGUI's And Progression

Hello everyone, like I usually say I’m new to scripting so please be patient with me. The way this works, is a player picks up a tool on the map (“Radio”). When the player equips the tool in their inventory, a ScreenGui appears (“RadioGui”). I want to script a progress bar, that only shows when the tool is equipped (along with the RadioGui). I need the progress bar to move, or increase, when a player clicks a certain part on the map while the tool is equipped. Here is the code I have now listed below; along with screenshots of my setup. So far the only thing that works is the RadioGui appearing once the tool is equipped. If anyone has any intel, helpful links, or experience with this, I would greatly appreciate your help.

local Ui = script:WaitForChild("RadioGui") -- Gui Name Here

script.Parent.Equipped:Connect(function()
	local ScreenGui = Ui:Clone()
	ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
end)

script.Parent.Unequipped:Connect(function()
	game.Players.LocalPlayer.PlayerGui:FindFirstChild(Ui.Name):Destroy()
end)
local Ui = script:WaitForChild("RadioGui") -- Gui Name Here
local progressBar = Ui:WaitForChild("ProgressBar") -- progress bar Frame name here
local clickPart = game.Workspace:WaitForChild("Radio1") -- The part you want the player to click on

script.Parent.Equipped:Connect(function()
	local ScreenGui = Ui:Clone()
	ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
end)

script.Parent.Unequipped:Connect(function()
	game.Players.LocalPlayer.PlayerGui:FindFirstChild(Ui.Name):Destroy()
end)

local function handleClick()
	-- Increase the progress bar size by a certain amount
	progressBar.Size = progressBar.Size + UDim2.new(1, 1, 1, 1) -- Adjust the amount as needed
end

clickPart.ClickDetector.MouseClick:Connect(handleClick)

Screenshot 2023-12-12 230223

In the screenshot, what is labeled “Script” is just for a proximity prompt for the radio, the “LocalScript” is what I included above.
The part the player needs to click is labeled “Radio1”, and only consists of a click detector.

2 Likes

Apparently you’re cloning the ScreenGUI whereas the updating function weren’t assigning to the cloned GUI, the one you’re currently updating is the main progress bar and not from the main cloned GUI, and since ScreenGui is in another scope, it cannot be used outside unless variable is pure blank and assigned somewhere else

You don’t have to clone and place it inside PlayerGui, instead just parent the main ScreenGUI directly.

--removed some duplicate lines to prevent more issues
local Ui = script:WaitForChild("RadioGui") -- Gui Name Here

local progressBar = Ui:WaitForChild("ProgressBar") -- progress bar Frame name here
local clickPart = game.Workspace:WaitForChild("Radio1") -- The part you want the player to click on

script.Parent.Equipped:Connect(function()
	Ui.Parent = game.Players.LocalPlayer.PlayerGui --parents it to the PlayerGui
end)

script.Parent.Unequipped:Connect(function()
	Ui.Parent = script --returns the GUI back to localscript
end)

local function handleClick()
	-- Increase the progress bar size by a certain amount
	progressBar.Size = progressBar.Size + UDim2.new(1, 1, 1, 1) -- Adjust the amount as needed
end

clickPart.ClickDetector.MouseClick:Connect(handleClick)
1 Like