i am hoping this will be my last asking for help topic in this category but anyways, I’ve been trying to get a GUI to appear when a player touches a part, but not just one part, multiples. basically, i am using :GetChildren() to create a table of all the touch parts in a folder so that way, when a player touches either part, the GUI will appear
here is the script that i am using
local TouchPart = game.Workspace.Elevator:FindFirstChild("Touch"):GetChildren()
local Player = game.Players.LocalPlayer
function touched(hit)
local plrname = hit.Parent.Name
local Plr = game.Players:FindFirstChild(plrname)
if Plr then
Plr.PlayerGui.ElTpGui.MainFrame.Visible = true
end
end
function notTouch(hit2)
local plrname = hit2.Parent.Name
local Plr = game.Players:FindFirstChild(plrname)
if Plr then
Plr.PlayerGui.ElTpGui.MainFrame.Visible = false
end
end
TouchPart.Touched:Connect(touched)
TouchPart.TouchedEnded:Connect(notTouch)
if anyone could explain the issue to me or do whatever yall do, i’d really appreciate it
TouchPart represents a table here, so I see the issue.
Although, I have a few more notes:
Instead, do -
function touched(hit)
if not hit.Parent:FindFirstChild("Humanoid") and not game:GetService("Players"):FindFirstChild(hit.Parent) then return end
local plr = hit.Parent
local Plr = game.Players:GetPlayerFromCharacter(plr)
if Plr then
Plr.PlayerGui.ElTpGui.MainFrame.Visible = true
end
end