im looking to improve this script, the script checks if the user camera is above or below 500 studs, if it is above 500 studs, it stops seagulls and ocean from playing and plays sky, otherwise vice-versa.
local cam = workspace.CurrentCamera
local seagulls = workspace.seagull
local oceansound = workspace.ocean
local skysound = workspace.sky
local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name)
while true do
wait()
if cam.CFrame.Y < 500 then
seagulls.Playing = true
oceansound.Playing = true
skysound.Playing = false
elseif cam.CFrame.Y > 500 then
seagulls.Playing = false
oceansound.Playing = false
skysound.Playing = true
end
end
while true do task.wait()
if cam.CFrame.Y ~= 500 then
seagulls.Playing = cam.CFrame.Y < 500
oceansound.Playing = cam.CFrame.Y < 500
skysound.Playing = cam.CFrame.Y > 500
end
end
shortened the while loop
also not sure if this is intentional on your part, but no code runs if Y is 500
so just in case I put that if statement there
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local seagulls = workspace.seagull
local oceansound = workspace.ocean
local skysound = workspace.sky
the character variable should be defined like this instead
new code
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local seagulls = workspace.seagull
local oceansound = workspace.ocean
local skysound = workspace.sky
while true do task.wait()
if cam.CFrame.Y ~= 500 then
seagulls.Playing = cam.CFrame.Y < 500
oceansound.Playing = cam.CFrame.Y < 500
skysound.Playing = cam.CFrame.Y > 500
end
end
what if you were to switch .Playing to .Volume? how would the = cam.CFrame.Y parts be like, since there would already be an existing = for setting the sound volume?
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local seagulls = workspace.seagull
local oceansound = workspace.ocean
local skysound = workspace.sky
while true do task.wait()
if cam.CFrame.Y ~= 500 then
seagulls.Volume = cam.CFrame.Y < 500 and 0.5 or 0
oceansound.Volume = cam.CFrame.Y < 500 and 0.5 or 0
skysound.Volume = cam.CFrame.Y > 500 and 0.5 or 0
end
end
this is how the volume property would work(assuming the default volume is 0.5)
though changing the volume will not pause the song at all
If you wanted it to fade depending on how far up the camera is, what you can do is:
--remove the player, character, and players variables because they are used no where in the script
local cam = workspace.CurrentCamera
local seagulls = workspace.seagull
local oceansound = workspace.ocean
local skysound = workspace.sky
local runs = game:GetService("RunService")
runs.Heartbeat:Connect(function()
local y = cam.CFrame.Y
local vol = math.clamp(0.5 - math.clamp(0,y/1000),0,0.5)
seagulls.Volume, oceansound.Volume, skysound.Volume = vol,vol,vol
end)