Skybox not changing

I’m trying to make it so when the rocket leaves earth it changes skybox
However it changes the skybox back to original when I do anything like equip a tool
Server script

-- Server Script (Script)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local skyboxEvent = Instance.new("RemoteEvent")
skyboxEvent.Name = "ChangeSkyboxEvent"
skyboxEvent.Parent = ReplicatedStorage
local touchPart = script.Parent


local debounceTime = 3 -- seconds
local db = false
-- Function to handle when a player touches the part
local function onPartTouched(otherPart)
		print("t")
	local character = otherPart.Parent
	if character:IsA("Model") and character:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(character)
			skyboxEvent:FireClient(player, "ChangeSkybox")
		end
	end
-- Function to handle when a player stops touching the part
local function onPartEnd(otherPart)
	print("TF")
	local character = otherPart.Parent
	if character:IsA("Model") and character:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			skyboxEvent:FireClient(player, "ChangeSkybox1")
		end
	end
	end
-- Assuming you have a part named "TouchPart" in the game
 -- Change this to the actual part
touchPart.Touched:Connect(onPartTouched)
touchPart.TouchEnded:Connect(onPartEnd)

-- Client Script (LocalScript)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local skyboxEvent = ReplicatedStorage:WaitForChild("ChangeSkyboxEvent")

local db = false

local sound1 = Instance.new("Sound",workspace)
sound1.Looped = true
sound1.Volume = .2
sound1.SoundId = "rbxassetid://1837878394"
sound1.Name = "Sound1"



local sound2 = Instance.new("Sound",workspace)
sound2.Looped = true
sound2.Volume = .2
sound2.SoundId = "rbxassetid://14884823178"
sound2.Name = "Sound2"
-- Function to change the skybox
local function changeSkybox()
	task.wait(.5)
	sound2:Stop()
	sound1:Play()
	game.Lighting["black_ice"].SkyboxBk = "rbxassetid://6444884337" -- Change this to the skybox you want when you leave
	game.Lighting["black_ice"].SkyboxDn = "rbxassetid://6444884785"
	game.Lighting["black_ice"].SkyboxFt = "rbxassetid://6444884337"
	game.Lighting["black_ice"].SkyboxLf = "rbxassetid://6444884337"
	game.Lighting["black_ice"].SkyboxRt = "rbxassetid://6444884337"
	game.Lighting["black_ice"].SkyboxUp = "rbxassetid://6412503613"
	
end

-- Function to revert back to the default skybox
local function revertSkybox()
	sound1:Stop()
	sound2:Play()
	game.Lighting["black_ice"].SkyboxBk = "rbxassetid://11844076072" -- Change this to the Skybox you want when you're on the planet
	game.Lighting["black_ice"].SkyboxDn = "rbxassetid://11844069700"
	game.Lighting["black_ice"].SkyboxFt = "rbxassetid://11844067209"
	game.Lighting["black_ice"].SkyboxLf = "rbxassetid://11844063543"
	game.Lighting["black_ice"].SkyboxRt = "rbxassetid://11844058446"
	game.Lighting["black_ice"].SkyboxUp = "rbxassetid://11844053742"
	game.Lighting["black_ice"].SunTextureId = "rbxassetid://7060747225"
end

-- Listen for skybox change event from server
skyboxEvent.OnClientEvent:Connect(function(eventName)
	if eventName == "ChangeSkybox" then
		changeSkybox()
	elseif eventName == "ChangeSkybox1" then
		revertSkybox()
	end
end)
1 Like

Is the so called ‘touchPart’ the handle or a part from a tool?

1 Like

it is a part that is in workspace

1 Like

Okay then I don’t know how to help you sadly. :sad:

1 Like