Trying to get a locally changed skybox

Hello.

I’m trying to get a script that changes a skybox locally, for an obby.
I have made a simple yet working script. which sadly does not change it locally, but serversided

local Lighting = game.Lighting
local SkyF = game.ServerStorage.SkyFolder
local SkyB = SkyF.Sky

script.Parent.Touched:Connect(function()
	SkyB.Parent = Lighting
end)

Thank you! :grinning:

2 Likes

To change the sky locally, you will have to use a LocalScript.

I did, I tried many scripts, none work.

1 Like

You have to utilize LocalScripts, and remember that LocalScripts cannot access ServerStorage, so try putting the folders in ReplicatedStorage, as ServerStorage doesn’t replicate and is not accessible to clients. So try moving the SkyFolder to ReplicatedStorage and change the refer variable to

local SkyF = game.ReplicatedStorage.SkyFolder

Just tried right now, didn’t really work, nothing on output

Output screenshot above

Your LocalScript should be located in StarterPlayer > StarterPlayerScripts. I have modified your code to incorporate some script structure with Debounces to better support the idea you are going for.

EDITED:

local Lighting = game.Lighting
local SkyF = game.ReplicatedStorage.SkyFolder
local SkyB = SkyF.Sky
local part = game.Workspace.Part
local debounce = false

part.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(touched.Parent)
		if player then
			if player == game.Players.LocalPlayer then
				if debounce == false then
					debounce = true
					local SkyClone = SkyB:Clone()
					SkyClone.Parent = game.Lighting
				end
			end
		end
	end
end)

image

You can try this:

-- LocalScript inside of StarterGui or StarterCharacterScripts
-- Place your SkyFolder into ReplicatedStorage

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local part = -- path to your part in the workspace
local folder = ReplicatedStorage:WaitForChild("SkyFolder")
local sky= folder:WaitForChild("Sky")

local connection

connection = part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player then
        sky.Parent = game.Lighting
        connection:Disconnect()
    end
end)
1 Like

Weirdly enough, it isn’t local? I tried it using PlayerEmulation on Roblox Studio.

Could you provide a screenshot of the Explorer tab and where you are placing things? This would further help us to see what may be the issue. I have provided a screenshot in my recent above forum post that shows where you should be placing your assets.

Okay,

hope it helps.

Everything seems to be placed where it should… Have you changed the variable that refers to Part?

For your case according to the screenshot, this should be changed to:
local touchpart = game.Workspace.SkyboxChanging

Used the copy you made, weirdly enough, still does the same, is it Player Emulation service (on the server screen, it’s the default skybox)? or is it the script?

Going to test with my friend.

Try using the normal test feature in Studio, that’s what I’ve been using to test the file.

image

Click the first button (Play)image

For me, this is what I see before:

And after the button is stepped on:
image

It isn’t client sided, which me and my friend just tested out,

1 Like

We can use discord to further talk about this, my discord is hexagon#4116

My sincere apologies, I’ve located where the error was which was the script checked for any player, this time it checks to see if it is the LocalPlayer that is pressing the button!
Here is the updated code, I will also correct the code provided in previous forum posts.

local Lighting = game.Lighting
local SkyF = game.ReplicatedStorage.SkyFolder
local SkyB = SkyF.Sky
local part = game.Workspace.Part
local debounce = false

part.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(touched.Parent)
		if player then
			if player == game.Players.LocalPlayer then
				if debounce == false then
					debounce = true
					local SkyClone = SkyB:Clone()
					SkyClone.Parent = game.Lighting
				end
			end
		end
	end
end)
5 Likes