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: Hi!

Previous Thread :: Next Thread 
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 09:14 PM
Can someone help me with tools? I want it to slash up and down.
how would I do that?
I have this:

function swordUp()
Tool.GripForward = Vector3.new(-1,0,0)
Tool.GripRight = Vector3.new(0,1,0)
Tool.GripUp = Vector3.new(0,0,1)
end

function swordOut()
Tool.GripForward = Vector3.new(0,0,1)
Tool.GripRight = Vector3.new(0,-1,0)
Tool.GripUp = Vector3.new(-1,0,0)
end

but i dunno how to fire it! D:





Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 09:26 PM
anyone? D:
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Dec 2013 09:28 PM
You want to fire it when they click or?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
01 Dec 2013 09:29 PM
Hmm... this might work, but I'm not sure:

Assuming that the 'tool' is the parent of the script:


local active = false
script.Parent.Activated:connect(function()
if (active) then return end
active = true
swordOut()
Wait(0.25)
swordUp()
active = false
end)
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:04 PM
Cool, ty
question:

wht is the Activated connection?
What do you have to do to activate?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
01 Dec 2013 10:06 PM
The Activated event is fired when the player clicks
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:09 PM
hmmm

local active = false -- why did you addthis?
script.Parent.Activated:connect(function()
if (active) then return end -- why did you add this?
active = true
swordOut()
Wait(0.25)
swordUp()
active = false
end)

I don't really understand why you added active... is it like

if false then return end -- because activate is false?
why would you add that?
Please help, im lost.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
01 Dec 2013 10:11 PM
Debouce.

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
01 Dec 2013 10:12 PM
I lied.

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:15 PM
what?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Dec 2013 10:16 PM
It's debounce, so the function can only run after the wait(0.25)
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
01 Dec 2013 10:18 PM
He added activate as a debounce. Debounce is a method of stopping an event from firing too fast. Since events are coroutines to prevent players from spamming up the animation and causing glitches, debounce allows the animation to run only once at a time. Also, return ends a function so thats why he put that.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:18 PM
but, the variable that calls it true is not inside of the function, so it only does so once.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
01 Dec 2013 10:19 PM
You don't want it to be inside the function. The idea is to restrict the function from working if it is already active.

Otherwise, you could have the function running 5 times at the SAME time (since events spawn new co-routined threads).
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:45 PM
Wait... wouldn't it only work once, since it's not in a loop or function?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
01 Dec 2013 10:50 PM
It's simply a variable sitting there. Since it's in the global scope of the script, it won't be removed.


local x = 0
function Increase()
local y = 0
y = y + 1
x = x + 1
end

Increase()
Increase()
Increase()

'x' is outside the function, but can still be used.
'y' on the other hand is created within the function, and is deleted from memory after (or soon after) the Increase function is completed.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 10:56 PM

Oh, I see.'I guees this line confused me

if (active) then return end -- Isn't it always going to be "false" because you put it that way?
when u said it was true, and the function ends, isn't that memory deleted so it starts over again?

My question: How can it progress if it is always (active)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Dec 2013 10:58 PM
local active = false --So it starts out false
script.Parent.Activated:connect(function() --Click
if (active) then return end --if it's true return end
active = true --make it true, so any new clicks will just stop
swordOut() --blah
Wait(0.25) --blah
swordUp() --bkah
active = false --make it false so any new clicks will start working again
end)
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 11:01 PM
Ok, now we're getting somewhere


if (active) then return end --if it's true return end


Why true?
it just said above that it was false!
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Dec 2013 11:03 PM
well if it's true, we don't run the function to keep running, return will stop the function.

we make it true so we HAVE to wait until after the swordUp function has been called, so then people can't glitch the animation
Report Abuse
RyanDolan123 is not online. RyanDolan123
Joined: 05 Mar 2009
Total Posts: 17919
01 Dec 2013 11:04 PM
Isn't it like...

Slash = Instance.new("StringValue",Sword)
Slash.Name = "toolanim"
Slash.Value = "slash" --or maybe it's Slash


And then the animation script slashes your arm?
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 11:07 PM
no no no!

if active == true then return end --if it's true return end
why did u say (active) means true?

shouldnt it be this?


if active == true then return end


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Dec 2013 11:08 PM
if active then

if really checks for a non false/nil value, so you can do:

if active == true then
if active ~= false then
if not active == false then
if not active ~= true then

But really, if active is pretty much saying:
if active isn't false or nil
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
01 Dec 2013 11:08 PM
Put into more plain English:


Set 'active' to 'FALSE'

TASK Activated: {
If 'active' is 'TRUE,' stop now! Else, continue on...
Set 'active' to 'TRUE'!
Do some sort of animation
Wait for 0.5 seconds
Set 'active' to 'FALSE!'
}

OnActivated, do TASK Activated

-------------------------------------

Notice how when TASK Activated is running, 'active' is set to true. That way, if the task is called again while the animation is still running, it won't overlap and run overtop of it. Instead it will simply stop the intruding request and let the other one do its job.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
01 Dec 2013 11:10 PM
Ok, I get it ty for all support
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