User:Outofspace/ON-OFF Button: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Outofspace
=o, SOFTWARE PROBLEM ALERT!!
>Outofspace
No edit summary
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
__TOC__
__TOC__


==My Script==
==The Script==


Completely unorganized and here mainly for archival purposes. I haven't updated this script in 4-5 months.
Changes the skybox from night to day.


<pre>
<pre>
--On/Off Button
--On/Off Button
--OutOfSpace
--OutOfSpace
script.Name = "On/Off-Script_Version_0.5b"
--1.0b
local ma = Instance.new("Message")
 
ma.Parent = game.Workspace
script.Name = "On/Off-Script_Version_1.0b"
ma.Text = "Starting..."
script.Parent = game.Workspace
wait(0.5)
 
game.Workspace.Message.Text = "Creating Brick..."
a = game.Workspace:GetChildren()
wait(0.1)
 
for i = 1, #a do
if a[i].Name == script.Name then
a[i]:Remove()
end
end
 
local b = Instance.new("Part")
local b = Instance.new("Part")
b.Parent = game.Workspace
b.Parent = game.Workspace
b.Name = "Button"
b.Name = "Head"
b.Size = Vector3.new(5, 1 ,5)
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")
local m = Instance.new("Model")
m.Parent = game.Workspace
m.Parent = game.Workspace
m.Name = "Ready"
m.Name = "Waiting..."
game.Workspace.Message.Text = "(Model)DONE!"
 
wait(0.1)
b.Parent = m
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")
local h = Instance.new("Humanoid")
h.Parent = game.Workspace.Ready
h.Parent = m
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")
local c = Instance.new("ClickDetector")
c.Parent = game.Workspace.Ready.Head
c.Parent = b
c.MaxActivationDistance = 100
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")
local s = Instance.new("Script")
s.Parent = game.Workspace
s.Parent = game.Workspace
Line 66: Line 53:
isOn = true
isOn = true
game.Workspace.On.Head.BrickColor = BrickColor.new(21)
game.Workspace.On.Head.BrickColor = BrickColor.new(21)
        game.Lighting.TimeOfDay = "00:00:00"
game.Workspace.On.Name = "Off"  
game.Workspace.On.Name = "Off"  
end
end
Line 72: Line 60:
isOn = false
isOn = false
game.Workspace.Off.Head.BrickColor = BrickColor.new(28)
game.Workspace.Off.Head.BrickColor = BrickColor.new(28)
        game.Lighting.TimeOfDay = "14:00:00"
game.Workspace.Off.Name = "On"
game.Workspace.Off.Name = "On"
end
end
Line 87: Line 76:


s.Disabled = false
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()
</pre>
==Simple Toggle Utility==
<b>BY MINDRAKER</b>
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:
<pre>
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)
sad = s:clone()
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
s:Remove()
end
sad.Parent = b
 
script.Parent.Selected:connect(onSelected)
</pre>
</pre>
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.  {{User:Mindraker/sig}} 05:28, 27 August 2008 (CDT)

Latest revision as of 03:11, 15 December 2008

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

The Script

Changes the skybox from night to day.

--On/Off Button
--OutOfSpace
--1.0b

script.Name = "On/Off-Script_Version_1.0b"
script.Parent = game.Workspace

a = game.Workspace:GetChildren()

for i = 1, #a do
if a[i].Name == script.Name then
a[i]:Remove()
end
end

local b = Instance.new("Part")
b.Parent = game.Workspace
b.Name = "Head"
b.Size = Vector3.new(5, 1 ,5)

local m = Instance.new("Model")
m.Parent = game.Workspace
m.Name = "Waiting..."

b.Parent = m

local h = Instance.new("Humanoid")
h.Parent = m

local c = Instance.new("ClickDetector")
c.Parent = b
c.MaxActivationDistance = 100

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.Lighting.TimeOfDay = "00:00:00"
	game.Workspace.On.Name = "Off" 
end

function off()
	isOn = false
	game.Workspace.Off.Head.BrickColor = BrickColor.new(28)
        game.Lighting.TimeOfDay = "14:00:00"
	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

sad = s:clone()
s:Remove()
sad.Parent = b