Line 4 is throwing the error Backpack is not a valid member of Player. I can't see anything wrong with it. Can anybody help me?
while true do players = game.Players:GetChildren() for p = 1, #players do if players[p].Backpack.Spawned.Value == true then if players[p].PlayerGui.AmbienceDay.IsPlaying == false then players[p].PlayerGui.AmbienceDay:Play() end if players[p].PlayerGui.AmbienceNight.IsPlaying == false then players[p].PlayerGui.AmbienceNight:Play() end mult = 1 if players[p].PlayerGui.InsideCheck.Inside.Value == true then mult = 0.1 end players[p].PlayerGui.AmbienceDay.Volume = game.Lighting.Weather.DayVolume.Value * mult players[p].PlayerGui.AmbienceNight.Volume = game.Lighting.Weather.NightVolume.Value * mult end end wait(0.5) end
while true do players = game.Players:GetPlayers() -- GetPlayers only gets Player objects. This is important if a non-Player object gets placed in Players for some reason. for _, plr in ipairs(players) do -- This is a generic for. The only change to the below code is that `players[p]` becomes simply `plr`: if plr:FindFirstChild("Backpack") and plr.Backpack.Spawned.Value then -- This addition should fix your error. It won't run the rest of the code (including the second half of the `if` statement) unless the Backpack exists. if not plr.PlayerGui.AmbienceDay.IsPlaying then plr.PlayerGui.AmbienceDay:Play() end if not plr.PlayerGui.AmbienceNight.IsPlaying then plr.PlayerGui.AmbienceNight:Play() end mult = 1 if r.PlayerGui.InsideCheck.Inside.Value then mult = 0.1 end plr.PlayerGui.AmbienceDay.Volume = game.Lighting.Weather.DayVolume.Value * mult plr.PlayerGui.AmbienceNight.Volume = game.Lighting.Weather.NightVolume.Value * mult --In the above `if` statements, I removed the `== true` and `== false`. `== true` is never explicitly necessary, and `== false` becomes `== true` when you use the `not` keyword on the expression. end end wait(0.5) end