Currently I am building a system that assigns different tags to players when they enter a zone as part of the core feature of my game. The future itself works perfectly the first time players use it using the ZonePlus Module (link here for breakdown). This works fine until the player dies and then respawns. When this occurs the ZonePlus Module does not identify when the player enters the zone and doesn’t assign the proper tag as it did before. I know this is the case because I have seen other players complain about this same issue when they use the ZonePlus module however none of them seem to post their solutions.
Here are the scripts starting with the Corner script that takes the player and assigns it to there zones:
local Zone = require(game.ReplicatedStorage:WaitForChild("Zone"))
local Players = game:GetService("Players")
local cornersFolder = script.Parent:WaitForChild("Corners")
local cornerZones = {}
for _, part in ipairs(cornersFolder:GetChildren()) do
if part:IsA("BasePart") then
local zone = Zone.new(part)
table.insert(cornerZones, zone)
zone.playerEntered:Connect(function(player)
local tag = player:FindFirstChild("CurrentCorner")
if not tag then
tag = Instance.new("StringValue")
tag.Name = "CurrentCorner"
tag.Parent = player
end
tag.Value = part.Name
print(player.Name .. " entered " .. part.Name)
end)
zone.playerExited:Connect(function(player)
local tag = player:FindFirstChild("CurrentCorner")
if tag then
tag.Value = "NoCorner"
print(player.Name .. " left corner → NoCorner")
end
end)
end
end
-- I added this parts to try to combat the issue and re-add players to the zone when they die but it didn't work
local function reAddToZones(player, character)
local hrp = character:FindFirstChild("HumanoidRootPart") or character:WaitForChild("HumanoidRootPart", 5)
if not hrp then
warn("Could not find HumanoidRootPart for", player.Name)
return
end
for i, zone in ipairs(cornerZones) do
if typeof(zone) == "table" and typeof(zone.addPlayer) == "function" then
zone:addPlayer(character)
else
warn("Zone at index", i, "is not a valid Zone object. Type:", typeof(zone))
end
end
end
for _, player in ipairs(Players:GetPlayers()) do
if player.Character then
reAddToZones(player, player.Character)
end
player.CharacterAdded:Connect(function(char)
wait(0.1)
reAddToZones(player, char)
end)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
wait(0.1)
reAddToZones(player, char)
end)
end)
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
wait(0.1)
reAddToZones(player, char)
end)
end)
This script itself is in the map. I have tried different solutions making scripts inside of ServerScriptStorage and putting code inside of different scripts in my game but nothing seems to work. It could possible be that I need to make a new script somewhere else, but I am unsure.
Please ask any questions if you want to see any other scripts and let me know any possible solutions that you have in mind. If you are unaware of the ZonePlus Module use the link provided to quickly freshen up on it. If you have any past experiences with the Module your input would be appreciated.
I think i found the root of the problem.
the issue is Zone/ZoneController/Tracker.
i inspected the source code to find the function that adds players and characters to the system.
local function playerAdded(player)
local function charAdded(character)
local humanoid = character:WaitForChild("Humanoid", 3)
if humanoid then
updatePlayerCharacters()
self:update()
for _, valueInstance in pairs(humanoid:GetChildren()) do
if valueInstance:IsA("NumberValue") then
valueInstance.Changed:Connect(function()
self:update()
end)
end
end
end
end
if player.Character then
charAdded(player.Character)
end
player.CharacterAdded:Connect(charAdded)
player.CharacterRemoving:Connect(function(removingCharacter)
self.exitDetections[removingCharacter] = nil
end)
end
consider
local humanoid = character:WaitForChild("Humanoid", 3)
if humanoid then
essentially, what i think is happening is ZonePlus is expecting a humanoid to be added after it starts waiting. but it already exists. WaitForChild eventually returns nil and the stuff required for the character to work in the module is not added.
what it should be, in stead is:
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then humanoid = character:WaitForChild("Humanoid",3) end
if humanoid then
...
else
...
end
I found it and added the updates like suggested so it looks like this:
local function playerAdded(player)
local function charAdded(character)
local humanoid = character:WaitForChild("Humanoid", 3)
if not humanoid then humanoid = character:WaitForChild("Humanoid",3) end
if humanoid then
updatePlayerCharacters()
self:update()
for _, valueInstance in pairs(humanoid:GetChildren()) do
if valueInstance:IsA("NumberValue") then
valueInstance.Changed:Connect(function()
self:update()
end)
end
end
end
end
if player.Character then
charAdded(player.Character)
end
player.CharacterAdded:Connect(charAdded)
player.CharacterRemoving:Connect(function(removingCharacter)
self.exitDetections[removingCharacter] = nil
end)
end
I then went to test if the Zones work after I die and respawn and it still doesn’t work.
Sorry for the late reply, but I tested this out and when the zone is working properly and players are switching corner tags the script is printing “Humanoid”. However, after the player dies and the script runs again it is no longer printing “Humanoid”. Along which this the zone isn’t working.
local function playerAdded(player)
local function charAdded(character)
local humanoid = character:WaitForChild("Humanoid")
if not humanoid then humanoid = character:WaitForChild("Humanoid",3) end
if humanoid then
updatePlayerCharacters()
self:update()
for _, valueInstance in pairs(humanoid:GetChildren()) do
print(humanoid)
if valueInstance:IsA("NumberValue") then
valueInstance.Changed:Connect(function()
self:update()
end)
end
end
end
end
So in summary when it prints “Humanoid” the script works but when it prints nothing after respawn the script doesn’t work.
I actually found the problem finally after all this time. If you are using the ZonePlus module on LocalClient and the functions is inside the Client… Better switch it to ServerScript and use RemoteEvents to pass the functions to the Client.
But there is no found solution with the Local Client sadly.