Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] How do I make a toggleable button that makes parts appear and disappear?

Asked by 4 years ago
Edited 4 years ago

Information:

  • I am not getting any errors
  • I already attempted this, it didn't work.
  • The parent of the script game.StarterGui.GraphicsGui.GraphicsButton
  • The script is a LocalScript
  • When I click the button nothing happens.
  • The folder :https://ibb.co/Kbc14Wj

Attempt:

local qualityhigh = true
function Click(mouse)
    if qualityhigh == true then
        script.Parent.Text = "Increase Graphics"
        game.Workspace.HighQuality:Destroy()
        qualityhigh = false
    end
    if qualityhigh == false then
        script.Parent.Text = "Decrease Graphics"
        local copy = game.Lighting.HighQuality:Clone()
        copy.Parent = game.Workspace
        qualityhigh = true
    end
end


script.Parent.MouseButton1Down:connect(Click)

Edit: I fixed it by changing the parent and using elseif:

Answer:

local qualityhigh = true
function Click(mouse)
    if qualityhigh == true then
        script.Parent.Text = "Increase Graphics"
        game.Workspace.HighQuality.Parent = game.Lighting
        qualityhigh = false
    elseif qualityhigh == false then
        script.Parent.Text = "Decrease Graphics"
        game.Lighting.HighQuality.Parent = game.Workspace
        qualityhigh = true
    end
end


script.Parent.MouseButton1Down:connect(Click)
0
Do you want this on the client or on the server? Dovydas1118 1495 — 4y
0
@Dovydas1118 Client Dave_Robertson 42 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Right, there is nothing much wrong with your script. If you want to destroy the clone, you're gonna need to name it. Naming your parts and using Instance:FindFirstChild() will be the key to destroying and cloning parts. Also, if you're using a function for only purpose, you might as well use an anonymous function to save yourself from naming things.

local qualityhigh = false --You should for the lower PC counterparts first.

script.Parent.MouseButton1Down:Connect(function() --Capitalise the connect, as it is deprecated. Also, if you're not using the parameter, don't use it.
    if not qualityhigh then --Same thing as if qualityhigh == false
        script.Parent.Text = "Decrease Graphics"
        local copy = game.Lighting.HighQuality:Clone()
        copy.Name = "LightPart" --You can name this whatever.
        copy.Parent = workspace --workspace and game.Workspace are the same thing.
        qualityhigh = true
    elseif qualityhigh then --Learning else and elseifs is the difference between level 1 and level 10 scripters.
        script.Parent.Text = "Increase Graphics"
        local copiedPart = workspace:FindFirstChild("LightPart")
        if copiedPart then --If the part exists (if not it returns nil)
            workspace.LightPart:Destroy()
            qualityhigh = false
        end
    end
end)
0
Doesn't work Dave_Robertson 42 — 4y
Ad

Answer this question