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

Why won't this work? (Removes local GUI when player touches brick)

function touch()
	Guy = game.Players:GetPlayerFromCharacter(touch.Parent)
	ha = guy.localgui.Gui1
	ha:Remove()
end

script.Parent.Touched:connect(touch)

3 answers

ha = guy.localgui.Gui1

From what I know, there is no such thing as localgui, only PlayerGui.

ha = guy.PlayerGui.Gui1

Tip: Always leave the Output window opened.

The best way to do this is to use anonymous functions:

See "in-code-comments" for explanation

----The following is untested code----
script.Parent.Touched:connect(function(hit) --//Whatever touches the brick, is now (in the script) called "hit"

	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then --//If what touched the brick is a player, then
		local Guy = game.Players:GetPlayerFromCharacter(hit.Parent) --//Gets the "Guy"
		local ha = Guy.PlayerGui:FindFirstChild("Gui1") --//Find the Gui
		if ha then --//If "ha" is not already destroyed / not in the player, then it will not continue
			ha:Destroy() --//Use "Destroy" instead of "Remove" because it completely removes the object
		end
	end
end)

Hope this helped you out, if so, make sure to accept my answer!

function touch()
    Guy = game.Players:GetPlayerFromCharacter(touch.Parent)
    ha = guy.localgui.Gui1 -- Problem isthe "guy" is not spelled like the variable. And localgui should be PlayerGui
    ha:Remove()
end

script.Parent.Touched:connect(touch)

So heres the fix

function touch()
    Guy = game.Players:GetPlayerFromCharacter(touch.Parent)
    ha = Guy.PlayerGui.Gui1
    ha:Remove()
end

script.Parent.Touched:connect(touch)

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