Hello! I need help on ZonePlus module! Basically, my script plays a random song when entered the zone; when they leave, it’ll stop playing that song, and play another (not implemented yet). However, when the player dies, it’ll replay, and sometimes overlaps the song. Please help!
local rs = game:GetService("ReplicatedStorage")
local module = require(rs.Zone)
local Container = workspace:WaitForChild("WhiteZone")
local Zone = module.new(Container)
local Song = script.Song:GetChildren()
Zone.playerEntered:Connect(function(plr)
print(plr.Name.." Entered")
while wait(1) do
local randomsong = Song[math.random(1, #Song)]
randomsong:Play()
randomsong.Ended:Wait()
end
end)
Zone.playerExited:Connect(function(plr)
print(plr.Name.." Left")
end)
local rs = game:GetService("ReplicatedStorage")
local module = require(rs.Zone)
local Container = workspace:WaitForChild("WhiteZone")
local Zone = module.new(Container)
local Song = script.Song:GetChildren()
local currentSong
local ended
Zone.playerEntered:Connect(function(plr)
print(plr.Name.." Entered")
ended = false
while wait(1) do
local randomsong = Song[math.random(1, #Song)]
currentSong = randomsong
randomsong:Play()
randomsong.Ended:Wait()
if ended then break end
end
end)
Zone.playerExited:Connect(function(plr)
print(plr.Name.." Left")
ended = true
currentSong:Stop()
end)