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

How can i make a GUI pop-up on the Touched event of a part?

Asked by 6 years ago
Edited 6 years ago

I have been looking on many tutorials online since i'm kinda new to Lua and none of the codes presented has worked for me, i found a promising one but when i gave it a try it didn't work

Here's the code:

game.Players.PlayerAdded:Connect(function(plr)
script.Parent.Touched:connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid") then
  plr.PlayerGui.questchat.Teleport.Visible = false
  wait(2)
  plr.PlayerGui.questchat.Teleport.Visible = true
 end
end)
end)?

At first i thought it was a problem with the names of the GUI and frames but everything checks out and still no output, no change of properties and no popup or closure of the GUI

0
Are you using filtering enabled? DogeDark211 81 — 6y
0
That tutorial is bad. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by
seith14 206 Moderation Voter
6 years ago
local Players = game:GetService('Players')

script.Parent.Touched:connect(function (hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        local char = hit.Parent
        if Players:FindFirstChild(char.Name) then
            local plr = Players:FindFirstChild(char.Name)
            plr.PlayerGui.questchat.Teleport.Visible = false
            wait(2)
            plr.PlayerGui.questchat.Teleport.Visible = true
        end
    end
end)

-- Didn't test but that should be right
0
Yep it worked, ty very much misterdimacugut 11 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Hello. This script will only work without filtering enabled.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --checks if it is a player
        local char = hit.Parent --gets the character
        local plr = hit.Parent::GetPlayerFromCharacter(char) --gets the player who touched the part
        plr.PlayerGui.questchat.Teleport.Visible = true --Sets the gui visible
    end
end)

Answer this question