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

How can I hide a GUI from player screen?

Hello, I am using this script:


local player = script.Parent.Parent.Parent.Parent.Parent
local money = player.leaderstats.Money
local itemstats = player.ItemStats.Item
local price = 350
local tool = game.Lighting:findFirstChild("DarkSword10")
local Box = script.Parent.Parent.Parent.Frame -- get the GUI to close


local function buy()
if money.Value >= price then
	if itemstats.Value == 9 then
		money.Value = money.Value - price
		local a = tool:clone()
		local text10 = script.Parent.TextButton
		a.Parent = player.Backpack
		local b = tool:clone()
		b.Parent = player.StarterGear
		itemstats.Value = 10
		text10.Visible = true
		Box.Visible = false -- here the code doesn't hide the GUI
		
	end

end
end
script.Parent.MouseButton1Down:connect(buy)

This is a script (not local) in StarterGUI, as you can see at line 20 I set to Visible false but the GUI still appears. Thanks.

2 answers

In order to get MouseButton1Down, a script must be run locally. User inputs cannot be detected by the server.

There's a lot of issues going on here. Firstly you shouldn't be removing stats from a player through a localscript. This should be done through a regular script using remote functions.

Ex. Have the localscript in the GUI fire an event, and having a script in serverscriptstorage remove the stats from the LocalPlayer when the event is fired.

Secondly, you can't run regular scripts in a GUI. It must be a localscript.

Third, this is highly inefficient

local player = script.Parent.Parent.Parent.Parent.Parent

When using a localscript and trying to find a player, you can just do

local player = game.Players.LocalPlayer

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