Information:
Attempt:
01 | local qualityhigh = true |
02 | function 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 |
14 | end |
15 |
16 |
17 | script.Parent.MouseButton 1 Down:connect(Click) |
Edit: I fixed it by changing the parent and using elseif:
Answer:
01 | local qualityhigh = true |
02 | function 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 |
12 | end |
13 |
14 |
15 | script.Parent.MouseButton 1 Down:connect(Click) |
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.
01 | local qualityhigh = false --You should for the lower PC counterparts first. |
02 |
03 | script.Parent.MouseButton 1 Down: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 |
18 | end ) |