Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a tool do something different when activated a second time?

So i am making a fishing pole that casts a line through making them transparent and then not again. So this works great but my problem is, when I want the tool to be activated again after its initial activation, I want the line to real back in. But I don't know how I could make it so the tool can be activated, then activated again, completing a second task.

This is what I have:

Tool.Activated:connect(function()
    SlashAnimLoaded:Play()--pay no attention to this stuff, it isn't realavant.
	Tool.A.Transparency = 1-- also Tool is script.Parent
	Tool.B.Transparency = 0
	wait(0.1)
	Tool.C.Transparency = 0
	Tool.B.Transparency = 1
	wait(0.1)
	Tool.D.Transparency = 0
	Tool.C.Transparency = 1
	wait(0.1)
	Tool.E.Transparency = 0
	Tool.D.Transparency = 1
--Don't know what to put here
		Tool.A.Transparency = 0
		Tool.B.Transparency = 1
		Tool.C.Transparency = 1
		Tool.D.Transparency = 1
		Tool.E.Transparency = 1
end)

2 answers

✓ Accepted answer

There is a very simple way you can do this. Here is one way, there may be others.

You could put an IntValue or NumberValue in this tool, then name it "Equips" or whatever you'd like. Then on equip, add 1 to the value, then check with an if. You will want to subtract 1 from the Value on the second try so it goes back to the first one!

This is what your finished script should look like:


Tool.Activated:connect(function()
    SlashAnimLoaded:Play()--pay no attention to this stuff, it isn't realavant.
    Tool.A.Transparency = 1-- also Tool is script.Parent
    Tool.B.Transparency = 0
    wait(0.1)
    Tool.C.Transparency = 0
    Tool.B.Transparency = 1
    wait(0.1)
    Tool.D.Transparency = 0
    Tool.C.Transparency = 1
    wait(0.1)
    Tool.E.Transparency = 0
    Tool.D.Transparency = 1
		if script.Parent.IntValue.Value == 2 then
       		Tool.A.Transparency = 0
     		Tool.B.Transparency = 1
        	Tool.C.Transparency = 1
        	Tool.D.Transparency = 1
        	Tool.E.Transparency = 1
			script.Parent.IntValue.Value = 1
	end
	script.Parent.IntValue.Value = 2 -- Actually Less typing by setting it this way, not adding
end)

Now, it's very important you have the value change at first where I put it because if it's before the script hits the If, then it will activate what should happen on second equip the first time. You may have to change the hierarchy and if you want this to stay as the second equip part, remove where value become 1 again!

If this helped, Up vote and Accept! Ask questions if it doesn't work or if you're confused!

8 comments

0

dav's way would appear to work as well

0

Sorry this doesn't work. It says that IntValue isn't a valid member of tool. I'm confused. script.Parent is the tool. is Intvalue supposed to be soemwhere else?

0

Do you know how to create an IntValue? You need to adjust my Hierarchy. I don't know where your script is or anything else! So you need to make an adjustment to direct the script correctly because I do not know, you didn't provide the information for that.

0

Lets say you have it like this Tool and inside of tool you have your parts, and the script and the int value. You will go to it by this: script.Parent.IntValue

0

What exactly is an intValue?

0

But yes I have my Tool, Inside my tool is the Parts and the Localscript.

1

IntValue is in "AdvancedObjects" for studio. You can make it with Instance.new("IntValue"). This is usually used like a Variable but it's not in the script so others can easily access it.

0

Ahh I see. This works! Thanks!

local 2ndTime = false

Tool.Activated:connect(function()
if not 2ndTime then
    SlashAnimLoaded:Play()--pay no attention to this stuff, it isn't realavant.
    Tool.A.Transparency = 1-- also Tool is script.Parent
    Tool.B.Transparency = 0
    wait(0.1)
    Tool.C.Transparency = 0
    Tool.B.Transparency = 1
    wait(0.1)
    Tool.D.Transparency = 0
    Tool.C.Transparency = 1
    wait(0.1)
    Tool.E.Transparency = 0
    Tool.D.Transparency = 1
else
        Tool.A.Transparency = 0
        Tool.B.Transparency = 1
        Tool.C.Transparency = 1
        Tool.D.Transparency = 1
        Tool.E.Transparency = 1
-- if you want to, once you activate a third time, do like the first: 2ndTime = false
end)

2 comments

0

This does not work either. It says malformed number near '2ndTime' I am not sure what this means at all.

0

lol i just forgot a things

This discussion is preserved as it was. New answers, comments, and votes are closed.