How do I make my skybox & atmosphere change locally when I go inside of a part?
Here’s an example, if Player1 is in level 1, the skybox would be a blue sky and atmosphere would be not that foggy. Then Player1 goes to level 2, the skybox changes to a desert and the atmosphere changes to a bit foggier.
After that, Player2 joins and is on level 1, with the same blue skybox and atmosphere because they are on level 1.
local part = workspace:WaitForChild("Level2Part")
local player = game.Players.LocalPlayer
part.Touched:Connect(function(hit)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if hitPlayer and hitPlayer == player then
-- change atmosphere and sky
end
end)
local player = game.Players.LocalPlayer
local part1 = workspace:WaitForChild("Level1Part")
local part2 = workspace:WaitForChild("Level2Part")
local part3 = workspace:WaitForChild("Level3Part")
function changeSky(hit, number)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if hitPlayer and hitPlayer == player then
game.ServerStorage.["Atmosphere"..number].Enabled = true
game.ServerStorage.["SkyLevel"..number].Enabled = true
end
end)
part1.Touched:Connect(function(hit)
changeSky(hit, 1)
end)
part2.Touched:Connect(function(hit)
changeSky(hit, 2)
end)
part3.Touched:Connect(function(hit)
changeSky(hit, 3)
end)
Make sure you have each sky have the right number afterwards
Side note: You can’t access the ServerStorage in a LocalScript
Put it inside ReplicatedStorage instead, that way it’ll be replicated across both the server/client
local player = game.Players.LocalPlayer
local part1 = workspace:WaitForChild("Level1Part")
local part2 = workspace:WaitForChild("Level2Part")
local part3 = workspace:WaitForChild("Level3Part")
function changeSky(hit, number)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if hitPlayer and hitPlayer == player then
game.ReplicatedStorage.["Atmosphere"..number].Enabled = true
game.ReplicatedStorage.["SkyLevel"..number].Enabled = true
end
end)
part1.Touched:Connect(function(hit)
changeSky(hit, 1)
end)
part2.Touched:Connect(function(hit)
changeSky(hit, 2)
end)
part3.Touched:Connect(function(hit)
changeSky(hit, 3)
end)
If you’re wanting to change the Skybox and Atmosphere, chances are you’ll probably need to add multiple separate Skyboxes inside ReplicatedStorage & adjust the settings of the Lighting properties if you want to change it from the local standpoint whenever a part gets touched
Perhaps something like this inside a LocalScript? (Adding onto Dandcx’s code)
local Player = game.Players.LocalPlayer
local Part1 = workspace:WaitForChild("Change1")
local Part2 = workspace:WaitForChild("Change2")
local PartDebounce = false
function ChangeThings(HitPart, NumberChange)
local Player = game.Players:GetPlayerFromCharacter(HitPart.Parent)
if Player and PartDebounce == false then
PartDebounce = true
for _, Skybox in pairs(game.Lighting:GetChildren()) do
if Skybox:IsA("Skybox") then
Skybox:Destroy()
end
end
if NumberChange == 1 then
local SkyboxClone = game.ReplicatedStorage.Skybox1:Clone()
SkyboxClone.Parent = game.Lighting
--Change other lighting properties here
elseif NumberChange == 2 then
local SkyboxClone = game.ReplicatedStorage.Skybox2:Clone()
SkyboxClone.Parent = game.Lighting
--Change other lighting properties here
end
wait(3)
PartDebounce = false
end
end
Part1.Touched:Connect(function(Hit)
ChangeThings(Hit, 1)
end)
Part2.Touched:Connect(function(Hit)
ChangeThings(Hit, 2)
end)
Problem with this: It changes globally for my game. If someone is in a specific area, the atmosphere and skybox changes for everyone, despite it being a local script in the character. Here’s my code.
local Player = game.Players.LocalPlayer
local Part1 = game.Workspace:WaitForChild("ExcaliburDimensionBox")
local Part2 = game.Workspace:WaitForChild("DefaultMap")
local Part3 = game.Workspace:WaitForChild("InfiniteAzure")
local PartDebounce = false
function ChangeThings(HitPart, NumberChange)
local Player = game.Players:GetPlayerFromCharacter(HitPart.Parent)
if Player and PartDebounce == false then
PartDebounce = true
for _, Skybox in pairs(game.Lighting:GetChildren()) do
if Skybox:IsA("Skybox") then
Skybox:Destroy()
end
end
if NumberChange == 1 then
local SkyboxClone = game.ReplicatedStorage.SkyEx:Clone()
SkyboxClone.Parent = game.Lighting
local AtmosphereClone = game.ReplicatedStorage.AtmosphereEx:Clone()
AtmosphereClone.Parent = game.Lighting
game.Workspace.CurrentMusic.Volume = 0
game.Workspace.ExcaliburDimension.Volume = 0.3
if game.Workspace.ExcaliburDimension.IsPlaying == false then
game.Workspace.ExcaliburDimension:Play()
end
--Change other lighting properties here
elseif NumberChange == 2 then
local SkyboxClone = game.ReplicatedStorage.SkyDefault:Clone()
SkyboxClone.Parent = game.Lighting
local AtmosphereClone = game.ReplicatedStorage.AtmosphereDefault:Clone()
AtmosphereClone.Parent = game.Lighting
game.Workspace.CurrentMusic.Volume = 0.3
game.Workspace.ExcaliburDimension.Volume = 0
game.Workspace.InfiniteAzureBGM.Volume = 0
game.Workspace.ExcaliburDimension:Stop()
game.Workspace.InfiniteAzureBGM:Stop()
--Change other lighting properties here
elseif NumberChange == 3 then
local SkyboxClone = game.ReplicatedStorage.SkyInfiniteAzure:Clone()
SkyboxClone.Parent = game.Lighting
local AtmosphereClone = game.ReplicatedStorage.AtmosphereEx:Clone()
AtmosphereClone.Parent = game.Lighting
game.Workspace.CurrentMusic.Volume = 0
game.Workspace.InfiniteAzureBGM.Volume = 0.3
if game.Workspace.InfiniteAzureBGM.IsPlaying == false then
game.Workspace.InfiniteAzureBGM:Play()
end
--Change other lighting properties here
end
task.wait()
PartDebounce = false
end
end
Part1.Touched:Connect(function(Hit)
ChangeThings(Hit, 1)
end)
Part2.Touched:Connect(function(Hit)
ChangeThings(Hit, 2)
end)
Part3.Touched:Connect(function(Hit)
ChangeThings(Hit, 3)
end)