I have the following code:
local ids = {} local function hasValue(tab, value) local contains = nil for k,v in pairs(tab) do if v == value then contains = k break; end end return contains end script.Parent.Detector.Touched:connect(function(obj) if obj.Name == "HumanoidRootPart" then local player = game.Players:GetPlayerFromCharacter(obj.Parent) if player then if hasValue(ids, player.UserId) == nil then print(player.UserId, "is here") table.insert(ids, player.UserId) end end end end) script.Parent.Detector.TouchEnded:connect(function(obj) if obj.Name == "HumanoidRootPart" then local player = game.Players:GetPlayerFromCharacter(obj.Parent) if player then local k = hasValue(ids, player.UserId) if k ~= nil then print(player.UserId, "left") ids[k] = nil end end end end)
It all works fine and dandy, the players UserId stays in the table until they leave the part... At least while they are in third person. As soon as they are in first person, and move or turn even the smallest amount, they constantly trigger the TouchEnded and Touched event. This ruins what I'm using this for, and so I need a way around it. How would I go about fixing this?