How can I make a script that detects if a player is in a zone but without it firing a bunch of times?
This script gives me a lot of prints in the output every time the player moves while in the zone.
local Zone = script.Parent
local Players = game:GetService("Players")
Zone.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Player entered the zone
print(player.Name .. " entered the zone")
player.multi.value = 5
end
end
end)
Zone.TouchEnded:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Player exited the zone
print(player.Name .. " exited the zone")
player.multi.Value = 1
end
end
end)