Help with Changing SkyBox After Teleportation

I’m a very novice scripter so please excuse me if there’s a really simple solution to my problem.

My goal is to make it so the SkyBox changes when a player is teleported from one location to another by touching a part at the new location.

The problem is that the game doesn’t recognize EarthSky as a valid member but it’s definitely there. I can’t do WaitForChild() because it’s a local script. So, I’m clueless on how to make the game wait for the part to load in order to recognize it, if that’s the correct way to go.

17:14:56.101  EarthSky is not a valid member of Folder "Workspace.SkyParts"  -  Client - SkyboxChange:5
  17:14:56.101  Stack Begin  -  Studio
  17:14:56.101  Script 'Players.Vovix.PlayerGui.SkyboxChange', Line 5  -  Studio - SkyboxChange:5
  17:14:56.101  Stack End  -  Studio

Here is the teleport script that operates fine, to my knowledge:

local TeleportPart1 = game.Workspace.TeleportParts.TownTP
local TeleportPart2 =game.Workspace.TeleportParts.EarthFormationTP1

TeleportPart1.Touched:Connect(function(hit)
	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w then
		w.CFrame = TeleportPart2.CFrame + Vector3.new(0, 5, 0)
		TeleportPart2.CanTouch = false
		wait(10)
		TeleportPart2.CanTouch = true


		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		humanoid.AutoRotate = false
		wait(0.1)
		humanoid.AutoRotate = true
	end
end)

Here is my SkyBox changing local script (in StarterGui and has a Sky as a child).

local lighting = game:GetService("Lighting")
local db = 1

wait(1)
game.Workspace.SkyParts.EarthSky.Touched:Connect(function()
	if db == 1 then
		db = 0
		script.EarthSky.Parent = lighting
	end
end)

I want to mention that there are two local scripts in StarterGui with the same functionality, one is for EarthSky and one is for TownSky. I wasn’t sure how to combine them. Basically, when the player joins, the SkyBox needs to be the TownSky. When they teleport, the SkyBox needs to change to EarthSky.

There’s a folder in Workspace called SkyParts with two parts, EarthSky and TownSky, which is what I’d like for the player to touch for the skybox to change.

It’s weird, too, because the parts change the SkyBox fine if they’re close to each other. But the moment I move the part away to the teleported location, it doesn’t see EarthSky in the hierarchy.

I’d also like to note that the EarthSky works after the player resets in the area where the second teleporter is located (where their new spawn is). But, not at the start after they teleport.

I lowkey do not understand your script, but I know you can change lightning but simply removing the current one, (ie just parent it somewhere thats not lighting or destroy, and clone/parent a new sky into lighting)

StarterGui won’t detect things like game.Workspace.SkyParts.EarthSky.Touched or be able to change script.EarthSky.Parent. Put the script in StarterPlayerScripts or StarterCharacterScripts

1 Like

I knew it was a stupid, simple solution. I was scrolling on YouTube and trying to figure it out forever. Thanks so much.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.