Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

Do you want this on the client or on the server?

0

@Dovydas1118 Client

1 answer

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)

1 comment

0

Doesn't work

This discussion is preserved as it was. New answers, comments, and votes are closed.