I want to make it so the script only gives stats and deals damage to the player that is in the zone. The issue is that whenever there are two players, the game ends up giving stats and dealing damage to both of them as long as one of them is in the zone. If there are any inefficiencies or better ways to do this code please lmk as i’m still not sure as to how to go about this.
local Zone = require(game.ReplicatedStorage.Zone)
local container = script.Parent
local zone = Zone.new(container)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local inZone = false
local Char = ""
zone.playerEntered:Connect(function(player)
inZone = true
Char = player.Character or player.CharacterAdded:Wait()
player.EndZoneMultiplier.Value = 2
end)
zone.playerExited:Connect(function(player)
inZone = false
player.EndZoneMultiplier.Value = 1
end)
while task.wait(1.5) do
if inZone == true and Char ~= "" then
local humanoid = Char:WaitForChild("Humanoid")
local endurance = player:WaitForChild("Endurance")
local multi = player.EndMultiplier
local zoneMulti = player.EndZoneMultiplier
local realmMulti = player.RealmMultiplier
humanoid.Health -= 10 * 5
if humanoid.Health > 0 then
endurance.Value += multi.Value * zoneMulti.Value * realmMulti.Value
end
end
end
end)
end)