Hello, im trying to make a skybox toggle button in my gui for my game can you help me
Hello, @keo164! This is quite simple to do. First, place your skybox in replicated storage, then insert a script into your GUI Button and write the following.
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
-- Maybe play a sound for it to be more immersive
local Sky = game.ReplicatedStorage.Sky:Clone() -- Whatever your skybox' name is
Sky.Parent = game.Lighting
end)
Simple, right? Hope this helped, and if it did. Mark it as a solution and if it didn’t, please let me know so I can fix it! Anyway, I hope you have an amazing rest of your day/night.
Edit
If you don’t want the Skyboxes spammed whenever someone clicks the button, just remove the
How to make a switch i meant that
I don’t understand, could you elaborate?
Like toggle the skybox on or off
I gave you a script about that- I assume you wanna make the switches move. I won’t give you a script this time, but it’s rather simple. To do this, you need to learn TweenService. Anyway, here’s the idea: Whenever you click the UI - it tweens to the other side by using :TweenPosition()
, then you check if the UIs’ position is where you Tweened it to. If it is, you continue on with the script.
Im trying to make a button to remove but it wont work
skybox = game.Lighting:WaitForChild("Sky")
skybox:Destroy()
Don’t destroy it, change it’s the location, also remove the :Clone() as it adds a new Skybox whenever you click the button.