How do I listen for events, for some amount of instances, in a single script?

I want to make a system in which a player, when entering some area will get a pop-up text message. There are supposed to be many different areas and what I am trying to figure out is how to listen for when a player enters these areas, in a single script or local script.

image

Right now I’m trying to listen for these events from a local script inside PlayerScripts, I tried making a for loop that will go through the folder with the zones and listen for an event, before that I tried to make it work with remote events but it turned out messy. I cant really find any topics that have a similar problem (probably because of my search skills)

1 Like

If you’re just trying to get a pop-up message then this should be done in a localscript

local Blighttown = workspace.BlighttownPart -- the regionpart
local player = game:GetService("Players").LocalPlayer
Blighttown.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
   if hit.Parent == player.Character then
      --Make the text show up
   end
end

end)
2 Likes

create a new tag named ‘Zone’
for every zone, give the tag to it and add a stringvalue (dont rename)
set the value to the popup text
in serverscriptservice, add a script:

local cs = game:GetService("CollectionService")
local zones = cs:GetTagged("Zone")

for _, zone in zones do
   local message = zone.StringValue.Value
   local ignore = {}
   zone.Touched:Connect(function(hit)
      if hit and hit.Parent:FindFirstChild("Humanoid") then
         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
         if player and not table.find(ignore, player) then
            table.insert(ignore, player)
            local text = player.PlayerGui...pathtotextlabel
            --show up text
         end
      end
   end)

   zone.TouchEnded:Connect(function(hit)
      if hit and hit.Parent:FindFirstChild("Humanoid") then
         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
         if player and table.find(ignore, player) then
            ignore[player] = nil
         end
      end
   end)
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.