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:

01local qualityhigh = true
02function Click(mouse)
03    if qualityhigh == true then
04        script.Parent.Text = "Increase Graphics"
05        game.Workspace.HighQuality:Destroy()
06        qualityhigh = false
07    end
08    if qualityhigh == false then
09        script.Parent.Text = "Decrease Graphics"
10        local copy = game.Lighting.HighQuality:Clone()
11        copy.Parent = game.Workspace
12        qualityhigh = true
13    end
14end
15 
16 
17script.Parent.MouseButton1Down:connect(Click)

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

Answer:

01local qualityhigh = true
02function Click(mouse)
03    if qualityhigh == true then
04        script.Parent.Text = "Increase Graphics"
05        game.Workspace.HighQuality.Parent = game.Lighting
06        qualityhigh = false
07    elseif qualityhigh == false then
08        script.Parent.Text = "Decrease Graphics"
09        game.Lighting.HighQuality.Parent = game.Workspace
10        qualityhigh = true
11    end
12end
13 
14 
15script.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.

01local qualityhigh = false --You should for the lower PC counterparts first.
02 
03script.Parent.MouseButton1Down:Connect(function() --Capitalise the connect, as it is deprecated. Also, if you're not using the parameter, don't use it.
04    if not qualityhigh then --Same thing as if qualityhigh == false
05        script.Parent.Text = "Decrease Graphics"
06        local copy = game.Lighting.HighQuality:Clone()
07        copy.Name = "LightPart" --You can name this whatever.
08        copy.Parent = workspace --workspace and game.Workspace are the same thing.
09        qualityhigh = true
10    elseif qualityhigh then --Learning else and elseifs is the difference between level 1 and level 10 scripters.
11        script.Parent.Text = "Increase Graphics"
12        local copiedPart = workspace:FindFirstChild("LightPart")
13        if copiedPart then --If the part exists (if not it returns nil)
14            workspace.LightPart:Destroy()
15            qualityhigh = false
16        end
17    end
18end)
0
Doesn't work Dave_Robertson 42 — 4y
Ad

Answer this question