while wait(1) do
local hitbox = script.Parent.magicForestHitbox
local region = Region3.new(hitbox.Position - (hitbox.Size/2), hitbox.Position + (hitbox.Size/2))
local players = game.Players:GetPlayers()
local parts = game.Workspace:FindPartsInRegion3(region, nil, math.huge)
for i, v in pairs(parts) do
if v.Name == "HumanoidRootPart" then
if game.Players:GetPlayerFromCharacter(v.Parent) then
game.ReplicatedStorage.musicHandle:FireClient(game.Players:GetPlayerFromCharacter(v.Parent), "Play")
plr = table.find(players, v.Parent)
table.remove(players, plr)
elseif v.Parent:FindFirstChild("Monster") then
laserDeath(v.Parent)
end
end
end
for i, player in pairs(players) do
game.ReplicatedStorage.musicHandle:FireClient(player, "Stop")
end
end
This script is supposed to fire a remote event when youre in a region3.
game.ReplicatedStorage.musicHandle.OnClientEvent:Connect(function(play)
local music = game.Workspace.musicHandler:GetChildren()
if play == "Play" then
if script.magicForestMusic.IsPlaying == false then
script.magicForestMusic:Play()
for i, v in pairs(music) do
v.Volume = 0
end
end
elseif play == "Stop" then
script.magicForestMusic:Stop()
for i, v in pairs(music) do
v.Volume = .5
end
end
end)
This is the remote event. I’ve tested it a few times- sometimes it doesn’t work at all, sometimes I enter the region and it keeps starting over…?
Is it because the part where it removes you from the player table so it doesn’t make you restart is remade at the beginning? But that shouldn’t matter, because it will see that you’re in it again…? I have no idea…
The weirdest part? I ported this over from a test place, and it worked perfectly in the test place. No errors- pretty sure I’ve changed all the variables I needed to.
EDIT: I believe I know the issue. Since this is being cloned, eventually there can be multiple forests. This means that at some point, you could be in one forest, but not in the other, and since the forest check-if-you’re-in-it script is constantly running, one forest says you’re in the forest, and plays music, the other says you aren’t, and stops it.
How do I fix this?