Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
function touch()
    Guy = game.Players:GetPlayerFromCharacter(touch.Parent)
    ha = guy.localgui.Gui1
    ha:Remove()
end

script.Parent.Touched:connect(touch)

3 answers

Log in to vote
0
Answered by 7 years ago
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.

Ad
Log in to vote
0
Answered by
nanaluk01 247 Moderation Voter
7 years ago
Edited 7 years ago

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!

Log in to vote
-1
Answered by
Scrxptss -13
7 years ago
Edited 7 years ago
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)

Answer this question