So as the title suggests, I just wanted to know what should i use if i wanted to make it so if a player enters a that is uncollidable, an event is triggered, and until they leave the part, another event triggers.
An example of this would be like when a player enters a room a sound plays and when he leaves the room, the sound stops playing.
Or when someone enters a location like a cave, the lighting changes making it dark, and when they leave the lighting returns to normal.
All i need to know is what i need to use in order to make this come to life.
All Parts have a .Touched and .TouchEnded event which you can connect to
local Players = game:GetService('Players')
local Part = workspace.Part
Part.Touched:Connect(function(touch)
for _, player in pairs(Players:GetPlayers()) do
if touch:IsDescendantOf(player.Character) then
print(`{player} entered zone`)
end
end
end)
Part.TouchedEnded:Connect(function(touch)
for _, player in pairs(Players:GetPlayers()) do
if touch:IsDescendantOf(player.Character) then
print(`{player} left zone`)
end
end
end)
While that would work, I wouldn’t recommend using Touch events as they are unpredictable at times, usually Region3s work better.
script.Parent.Touched:Connect(function(toucher)
if toucher.Parent:FindFirstChild("Humanoid") then
game.Workspace.Sounds["Underwater Ambience"]:Play()
end
end)
script.Parent.TouchEnded:Connect(function(toucher)
if toucher.Parent:FindFirstChild("Humanoid") then
game.Workspace.Sounds["Underwater Ambience"]:stop()
end
end)
But the problem is that its kinda glitchy, since as you mention, its unpredictable at times. But for the most part it does work. I might actually try Region3s instead.
The third method is generally the most accurate but is likely in excess for what you need for precision. Although, it does accept a Part to denote a region which may be useful in your case.
Another thing to note is that .Touched events for client-owned parts interacting with other client-owned parts (like the player character) are more accurately reported when the event is also bound on the client. (With the exception of fast moving stuff which is just generally not registered well with .Touched)