I’m having great trouble attempting to get the zones to work after the player respawns. I have these safe zones for the player when they spawn, and if they exit them they should go away. They do. However, when the player respawns, the playerEntered and playerExit events literally don’t fire. Here is my localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Zone = require(ReplicatedStorage:WaitForChild("Zone"))
local ZoneEvent = ReplicatedStorage:WaitForChild("ZoneEvent")
local container = workspace:WaitForChild("SafeZone")
local zone = Zone.new(container)
ZoneEvent.OnClientEvent:Connect(function()
print("fired")
local childReferences = {}
local canEnter = true
for _, child in ipairs(container:GetChildren()) do
child.Transparency = 1
childReferences[child] = true
local zone = Zone.new(child)
zone.playerEntered:Connect(function(player)
if canEnter then
child.Transparency = 0.5
end
end)
zone.playerExited:Connect(function(player)
canEnter = false
local transparencyTween = TweenService:Create(child, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Transparency = 1}, true)
transparencyTween:Play()
end)
end
end)
And here is my serverscript for firing the event:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ZoneEvent = ReplicatedStorage:WaitForChild("ZoneEvent")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
ZoneEvent:FireClient(player)
end)
end)
You set canEnter to false when the player leaves the zone, but you never set it back to true, so the condition to set the transparency will never pass. You should just remove this variable as it serves no use.
Well, I made this variable so that when the player re-enters the zone, the effects aren’t applied. I made it so when you walk out of the zone, it goes away.
Hello, what’s the optimal amount of zones recommended for performance? (client) because in my game i wanna have zones for each EggStand, and I was wondering if there is a recommended max limit number for zones.
Since i wanna check if player entered the Stand’s Hitbox then pop ui else pop ui off
constantly getting errors about calling a nil value
even made a completely fresh game and put in a simple script and still not working
anyone else getting this problem?
Hi! How would I detect the exact name of the zone part that a player has entered inside a container? For example, I have a container with 10 safezones in it all named safezone1, safezone2, etc. I want “safezone7” to be printed out, but I can’t find any API for that.
Hey, you can get the parts the player is touching with:
local touchingZonesArray, touchingPartsDictionary = ZoneController.getTouchingZones(player)
The parts are within touchingPartsDictionary.
If you need to listen for players entering/exiting these parts, you would make every part into it’s own zone. Creating more zones adds minimal-to-no additional impact to performance.