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

From Legacy Roblox Wiki
Jump to navigationJump to search
>Outofspace
No edit summary
>Outofspace
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Simple Toggle Utility==
Here are a few On/Off scripts/tools that you can use.
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:
__TOC__
 
==The Script==
 
Changes the skybox from night to day.


<pre>
<pre>
brickName = "Toggle"
--On/Off Button
valueName = "On/Off"
--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 onButton1Down(mouse)
function on()
local targ = mouse.Target
isOn = true
if targ~=nil then
game.Workspace.On.Head.BrickColor = BrickColor.new(21)
if targ.Name == brickName then
        game.Lighting.TimeOfDay = "00:00:00"
if targ:findFirstChild(valueName)~=nil then
game.Workspace.On.Name = "Off"  
if targ[valueName].Value == true then
targ[valueName].Value = false
print("one")
else
targ[valueName].Value = true
print("two")
end
end
end
end
end
end


function onSelected(mouse)
function off()
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
isOn = false
game.Workspace.Off.Head.BrickColor = BrickColor.new(28)
        game.Lighting.TimeOfDay = "14:00:00"
game.Workspace.Off.Name = "On"
end
end


script.Parent.Selected:connect(onSelected)
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
</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