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: New to scripting - functions stacking?

Previous Thread :: Next Thread 
bloberous is not online. bloberous
Joined: 07 Jun 2009
Total Posts: 299
14 Jul 2016 11:37 PM
I wanted to make a brick move 30 times by one stud every time on the x-axis whenever it is touched. It works fine, but if you touch it repeatedly, it'll jitter around meaning (I think) that the function is stacked multiple times. How do I make it so that when it is touched, the function cannot be called until it is finished?



function move(hit)
if hit.Parent:findFirstChild'Humanoid' ~= nil
then local x = script.Parent.Position.X
for i = 1, 30, 1 do
script.Parent.Position = Vector3.new(x+i, script.Parent.Position.Y, script.Parent.Position.Z)
wait(1)
end
end
end

script.Parent.Touched:connect(move)
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
14 Jul 2016 11:40 PM
The thing is, it's finished in a fraction of a second. So if you touch the brick, the touch event will be getting triggered like 10 times. We use a debounce for this

db=false
script.Parent.Touched:connect(function(hit)
if db==false then db=true
if hit.Parent:findFirstChild'Humanoid' ~= nil
then local x = script.Parent.Position.X
for i = 1, 30, 1 do
script.Parent.Position = Vector3.new(x+i, script.Parent.Position.Y, script.Parent.Position.Z)
wait(1)
end
end
wait(1)
db=false
end)


Report Abuse
Titanicman882ftlong is not online. Titanicman882ftlong
Joined: 14 Aug 2012
Total Posts: 430
14 Jul 2016 11:41 PM
You create a Boolean. The first thing is put local Toggle = false, and the top of the script, not the function.

Before the if, put Toggle = true

In the for loop, put if Toggle == false then

After the script.Part string, put else return end

After the wait, put Toggle = false
Report Abuse
bloberous is not online. bloberous
Joined: 07 Jun 2009
Total Posts: 299
14 Jul 2016 11:49 PM
That makes so much sense! Thanks heaps from the both of you!
Report Abuse
bloberous is not online. bloberous
Joined: 07 Jun 2009
Total Posts: 299
14 Jul 2016 11:58 PM
Actually I have another problem with this. When the character touches it as it is moving, it goes above the character as to not interfere with the character's position. Any way to prevent that too?
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
15 Jul 2016 12:07 AM
I think setting it's CFrame instead of it's position will do the trick.
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
15 Jul 2016 12:09 AM
Yeah, xx is correct.


Report Abuse
bloberous is not online. bloberous
Joined: 07 Jun 2009
Total Posts: 299
15 Jul 2016 12:14 AM
My God it is beautiful. It feels so good to make a script from scratch and have it work the way you want it to. Thanks for everyone's help!
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