generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: an "if" statement for scripting.

Previous Thread :: Next Thread 
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 05:37 PM
--This will not work.
--Even though I corrected the brick to be this..... It doesent work.


if script.Parent.Head.Name = "Head" then
script.Parent.Head.Transparency = .7
wait (5)
script.Parent.Noob.Name = "Fred" -- Noob is the name of the model with the Head in it.
script.Parent.Fred.Size.Vector3 = (5,7,8)
script.Parent.Position.Vector3 = (120,860)
-- It doesent really execute the script, i dunno why.
-- Also, how do I tell where The position is on the map? Does it say it somewhere?, Im lost right now.


Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:48 PM
if script.Parent.Head.Name == "Head" then
script.Parent.Head.Transparency = .7
wait (5)
script.Parent.Noob.Name = "Fred" -- Noob is the name of the model with the Head in it.
script.Parent.Fred.Size.Vector3 = (5,7,8)
script.Parent.Position.Vector3 = (120,860)
end

-Every function needs an end.
-When you're making a statement you have to make sure to write a statement:

Statements:
== (Exactly this)
>= (More or this)
~= (Not this)

etc..
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 05:49 PM
if script.Parent.Head.Name == "Head" then
script.Parent.Head.Transparency = .7
wait (5)
script.Parent.Noob.Name = "Fred" -- Noob is the name of the model with the Head in it.
script.Parent.Fred.Size.Vector3 = (5,7,8)
script.Parent.Position.Vector3 = (120,860)
You're setting a value. You're supposed to check for a value, when checking you do two "="s.
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:50 PM
Adam, you forgot an end :)
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 05:50 PM
Oh yeah.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 05:52 PM
What if I want this script to Go on and on?

would I give it a function name like this


Function turnnoobintofred ()


(script)





end
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 05:52 PM
Also, for Position.Vector3, how do I know what the position is?
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:53 PM
You would do something like this, every 1 second it will check if the statement is true and then It will execute the command if it is.

while true do wait(1)
if script.Parent.Head.Name == "Head" then
script.Parent.Head.Transparency = .7
wait (5)
script.Parent.Noob.Name = "Fred" -- Noob is the name of the model with the Head in it.
script.Parent.Fred.Size.Vector3 = (5,7,8)
script.Parent.Position.Vector3 = (120,860)
end
end
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:54 PM
Vector3 positons are determined by X, Y, Z. You can find them at properties and play with it. Every brick/model haves it.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 05:55 PM

Why did you put 2 ends? thats what's weird, I dont know how many "ends" I should put.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 05:56 PM
With every "if" there is one end.
At the end of a script there is one end.
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:57 PM
While is a function, so therefore it needs an end.

function()
end

while statement do
end

if statement do
end

And so on..
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:57 PM
And if you happen to combine them you do this:

while true do
if statement == true then
--what will happen!
end
end
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 05:58 PM
So, If I zoom around and put a brick somewhere, then click on the brick, the Position would be there?
Report Abuse
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
07 Oct 2013 05:58 PM
typo:

"==(exactly this)"

correction:

Double equal signs (==) means "is equal to"
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 05:58 PM
The position would be shown in his properties, yes. First number would be X, second Y and third Z.
Report Abuse
stephen1182 is not online. stephen1182
Joined: 31 Aug 2010
Total Posts: 4003
07 Oct 2013 06:06 PM
For loops need an end, anonymous functions need an end), functions need an end, if statements need an end, while statements need an end, et cetera.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 06:30 PM
Now I need help on touch functions, how would I make it so when I touch "Part" , the Part becomes more and more invisible (Transparecy).
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 06:32 PM
function ontouch (part)

Ontouch workspace.part.Transparency+1

-- I dunno, I looked at lualearners, and it didnt quite define what to do.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 06:34 PM


function touched(part) -- THIS IS FROM LUALEARNER!!!!

local humanoid = part.Parent:FindFirstChild("Humanoid") --FindFirstChild is a method of every object. This is a safe way to see if something is there, if you're not sure it will be.

if humanoid ~= nil then --humanoid will be nil if one wasn't found. This is making sure we have a character of some sort.

local player = game.Players:GetPlayerFromCharacter(humanoid.Parent) --GetPlayerFromCharacter is a method of Players. This allows you to get the player that the character is attached to.

if player then --Same as: if player ~= nil then. Just easier to type.

player:Destroy() --Kick the player from the game.

end

end

end
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 06:38 PM
Well, for that you would have to create a function which would run every time it is touched.

local brick = script.Parent.hit.Name
local db = true

function onTouched(hit)
if db == true then
elseif db == false then return
if script.Parent.brick.Transparency >= 1 then
for i = 1, 100 do wait(0.01)
script.Parent.brick.Transparency = script.Parent.brick.Transparency + i
end
elseif script.Parent.brick.Transparency <= 1 then
for i = 1, 100 do wait(0.01)
script.Parent.brick.Transparency = script.Parent.brick.Transparency - i
end
end
end
end

script.Parent.Touched:connect(onTouched)


I think this should work, If not I maybe have mistaken somewhere, haven't scripter for 2 years :)
Give it a shot. It should make it transparent at 1st touch and not transparent at second and so on..
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 06:39 PM
You can ask me what does any of this does if you're willing to. I will be glad to help If I will be able to!
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
07 Oct 2013 06:42 PM
Is db your function?

Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 06:44 PM
Sorry, I've just noticed I've created it so it makes your arms legs go invisible .__.
Try this:

local brick = script.Parent
local db = true

function onTouched(hit)
if db == true then
elseif db == false then return
if brick.Transparency >= 1 then
for i = 1, 100 do wait(0.01)
brick.Transparency = brick.Transparency + i
end
elseif script.Parent.brick.Transparency <= 1 then
for i = 1, 100 do wait(0.01)
script.Parent.brick.Transparency = script.Parent.brick.Transparency - i
end
end
end
end

script.Parent.Touched:connect(onTouched)

The problem I'm currently stuck at is that I have no idea how to make for function to raise by 0.01 per 0.01 seconds :/
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Oct 2013 06:45 PM
db is just a debounce, with that I am making sure that you can't touch it multiple times while the function is running, and while you're at that I've messed that up too!

local brick = script.Parent
local db = true

function onTouched(hit)
if db == true then
db = false
elseif db == false then return
if brick.Transparency >= 1 then
for i = 1, 100 do wait(0.01)
brick.Transparency = brick.Transparency + i
end
elseif script.Parent.brick.Transparency <= 1 then
for i = 1, 100 do wait(0.01)
script.Parent.brick.Transparency = script.Parent.brick.Transparency - i
end
wait(5)
db = true
end
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image