User:Outofspace/ON-OFF Button

From Legacy Roblox Wiki
Revision as of 01:24, 28 August 2008 by >Outofspace
Jump to navigationJump to search

Here are a few On/Off scripts/tools that you can use.

My Script

Completely unorganized and here mainly for archival purposes. I haven't updated this script in 4-5 months.

--On/Off Button
--OutOfSpace
script.Name = "On/Off-Script_Version_0.5b"
local ma = Instance.new("Message")
ma.Parent = game.Workspace
ma.Text = "Starting..."
wait(0.5)
game.Workspace.Message.Text = "Creating Brick..."
wait(0.1)
local b = Instance.new("Part")
b.Parent = game.Workspace
b.Name = "Button"
b.Size = Vector3.new(5, 1 ,5)
game.Workspace.Message.Text = "(Brick)Done!"
wait(0.1)
game.Workspace.Message.Text = "Creating Model..."
wait(0.1)
local m = Instance.new("Model")
m.Parent = game.Workspace
m.Name = "Ready"
game.Workspace.Message.Text = "(Model)DONE!"
wait(0.1)
game.Workspace.Message.Text = "game.Workspace.Button.Parent = game.Workspace.Ready"
wait(0.1)
game.Workspace.Button.Parent = game.Workspace.Ready
game.Workspace.Message.Text = "Done!"
wait(0.1)
game.Workspace.Message.Text = "Creating Humanoid..."
local h = Instance.new("Humanoid")
h.Parent = game.Workspace.Ready
game.Workspace.Message.Text = "(Humanoid)Done!"
wait(0.1)
game.Workspace.Message.Text = "Creating Head..."
wait(0.1)
game.Workspace.Ready.Button.Name = "Head"
game.Workspace.Message.Text = "(Head)Done!"
wait(0.1)
game.Workspace.Message.Text = "Creating ClickDetector..."
wait(0.1)
local c = Instance.new("ClickDetector")
c.Parent = game.Workspace.Ready.Head
c.MaxActivationDistance = 100
game.Workspace.Message.Text = "(ClickDetector)DONE!"
wait(0.1)
game.Workspace.Message.Text = "Creating Script..."
wait(0.1)
local s = Instance.new("Script")
s.Parent = game.Workspace
s.Disabled = true
s.Name = "ButtonScript"
s.Source = [[
script.Parent.Parent.Name = "On"

local isOn = true

function on()
	isOn = true
	game.Workspace.On.Head.BrickColor = BrickColor.new(21)
	game.Workspace.On.Name = "Off" 
end

function off()
	isOn = false
	game.Workspace.Off.Head.BrickColor = BrickColor.new(28)
	game.Workspace.Off.Name = "On"
end

function onClicked()
	
	if isOn == true then off() else on() end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()
]]

s.Disabled = false
game.Workspace.Message.Text = "(Script)Done!"
wait(0.1)
game.Workspace.Message.Text = "Copying Script..."
wait(0.1)
sad = game.Workspace.ButtonScript:clone()  --Right here, it creates a copy of game.Workspace.Model, and sets it as the variable "model"
game.Workspace.ButtonScript.Parent = nil  --This sets the game.Workspace.Model's parent to nothing, removing it from the game.
sad.Parent = game.Workspace.Ready.Head  --Sets the cloned object's Parent to the Workspace.
wait(0.4)
game.Workspace.Message.Text = "Done!"
wait(0.1)
game.Workspace.Message:Remove()

Simple Toggle Utility

BY MINDRAKER

Insert a Brick in the Workspace. Insert a BoolValue into that Brick. Name that BoolValue "OnOff". Just as before, you have a Hopperbin object in the StarterPack, and a script in the HopperBin. Insert the following into that script:

brickName = "Toggle"
valueName = "On/Off"

function onButton1Down(mouse)
	local targ = mouse.Target
	if targ~=nil then
		if targ.Name == brickName then
			if targ:findFirstChild(valueName)~=nil then
				if targ[valueName].Value == true then
					targ[valueName].Value = false
print("one")
				else
					targ[valueName].Value = true
print("two")
				end
			end
		end
	end
end

function onSelected(mouse)
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

script.Parent.Selected:connect(onSelected)

Upon clicking the mouse on the brick in Solo Mode, you can see the Output toggle between "one" and "two". You can easily manipulate this script to work for anything. MINDRAKER 05:28, 27 August 2008 (CDT)