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)
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
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)
-- 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)
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.
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?
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)