ZonePlus fails to work after death

This had been an issue for quite a bit of time, but it’s gotten very annoying now.

for _, zone_part in pairs(Containers) do
	local zones = Zone.new(zone_part)
	zones.localPlayerEntered:Connect(function()
		if debounce == false then return end
		debounce = false
		local regioninfo = script:FindFirstChild(zone_part.Name)
		
		local altered = regioninfo.Name
		print(altered)

		local sound = script.Sound
		sound:Play()

		local music = regioninfo.Sound

		if music.IsPlaying then
			TweenAudio(music, 4, {Volume = 0.5})	
		else
			music.Volume = 0
			music:Play()
			TweenAudio(music, 4, {Volume = 0.5})	
		end
                task.wait(4)
                debounce = true

       zones.localPlayerExited:Connect(function()
		local regioninfo = script:FindFirstChild(zone_part.Name)
		local music = regioninfo.Sound

		if music.IsPlaying then
			TweenAudio(music, 4, {Volume = 0})	
		end
	end)

For some odd reason, without dying, the code works flawlessly with no issues. However, after dying, there’s a chance that it will stop working - sometimes it will continue to work, but other times it will throw out error messages. Heck, sometimes it throws up error messages and still works. It’s weird.

Apparently on death, it can’t find it’s own child and treats it as nil, but I have no idea how to solve this. Could anybody help?
(The Module )ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries

1 Like

Just spent some time trying to read through the code and turns out, it is even more poorly written than I thought. Though I use ZonePlus, I never encountered the issue you are talking about, but if I do find smth I’ll lyk. Also the error seems to come from your script

Yeah this one was a very old script (1+ year ago); Never bothered fixing it because it was disabled for a majority of it’s lifespan.

I’ve been trying to go through it rn, but yeah I’ll probably just rewrite the entire thing lol, but I’m not really sure what would be an more optimal way to write this.