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 » Scripters
Home Search
 

Re: Why does my function fire when the game starts?

Previous Thread :: Next Thread 
klamman is not online. klamman
Joined: 06 Feb 2010
Total Posts: 436
08 Jul 2015 12:32 AM
function onTouched(msg)
a = Instance.new("Message", game.Workspace)
a.Text = msg
wait(5)
a:Remove()
end

script.Parent.Touched:connect(onTouched("Hello!"))

I'm relatively new to scripting, and I've been reading a lot on the wiki, but there are still a few scripts that I can't wrap my head around first. Can someone help me? Why does my function in this script fire without the Touched event firing (being fulfilled?)? (Hopefully that was syntactically correct) Thanks in advance.
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
08 Jul 2015 12:32 AM
Why does my mom smell like crap? Maybe I crapped on here. But I Really didn't. Maybe she crapped on her self.
Report Abuse
klamman is not online. klamman
Joined: 06 Feb 2010
Total Posts: 436
08 Jul 2015 12:35 AM
Essentially, what I'd like to do is make this script

function onTouched()
a = Instance.new("Message", game.Workspace)
a.Text = "Hello World!"
wait(5)
a:Remove()
end

script.Parent.Touched:connect(onTouched)

accept parameters. Obviously, I'm doing something wrong (as shown by my script above.)
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
08 Jul 2015 12:36 AM
Hi
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
08 Jul 2015 12:36 AM
You'd need to instantiate a separate function to handle the variable distribution.

function onTouched(msg)
a = Instance.new("Message", game.Workspace)
a.Text = msg
wait(5)
a:Remove()
end

script.Parent.Touched:connect(function()
onTouched("Hello!");
end)


Current Date; July 7th 2015, 10:36:45 pm
Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
08 Jul 2015 12:41 AM
^
Report Abuse
klamman is not online. klamman
Joined: 06 Feb 2010
Total Posts: 436
08 Jul 2015 12:43 AM
Thanks KOTwarrior, I really appreciate the help. I'm having a bit of trouble wrapping my head around the last bit.
(function()
onTouched("Hello!");
What exactly is going on here? The second part is connecting the event to the onTouched function and entering an argument, I get that. But where does "function()" come from? What exactly does it do? I apologize if I'm being too vague. Thanks in advance.
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
08 Jul 2015 12:43 AM
NOTICE ME TOO you ugly looking pancake fuqqin mother fuqer
Report Abuse
klamman is not online. klamman
Joined: 06 Feb 2010
Total Posts: 436
08 Jul 2015 12:46 AM
@someonedie,
Thanks for the help on the earlier thread, but I was actually looking for assistance with a different part of the script.
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
08 Jul 2015 12:48 AM
Thanks
Report Abuse
MakerModelLua is not online. MakerModelLua
Joined: 24 Feb 2013
Total Posts: 3544
08 Jul 2015 12:50 AM
What a waste of a 2011 account. The person behind the screen of that account has probably stole everything from the account ready and is ready to dispose of it.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
08 Jul 2015 01:00 AM
script.Parent.Touched -- Touched is an event

You can "connect" functions to events so the function will be fired when the event "fires".

script.Parent.Touched:connect(function to connect here)

But this method does not allow you to pass custom arguments, only default event arguments.

So instead you make a function connected to the event that will fire the other function with the argument(s) you want.

script.Parent.Touched:connect(function()
onTouched("stuff")
end)

-- This is all from my phone so XD
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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