Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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!

0
dav's way would appear to work as well alphawolvess 1784 — 9y
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? minikitkat 687 — 9y
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. alphawolvess 1784 — 9y
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 alphawolvess 1784 — 9y
View all comments (4 more)
0
What exactly is an intValue? minikitkat 687 — 9y
0
But yes I have my Tool, Inside my tool is the Parts and the Localscript. minikitkat 687 — 9y
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. alphawolvess 1784 — 9y
0
Ahh I see. This works! Thanks! minikitkat 687 — 9y
Ad
Log in to vote
0
Answered by
davness 376 Moderation Voter
9 years ago
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)
0
This does not work either. It says malformed number near '2ndTime' I am not sure what this means at all. minikitkat 687 — 9y
0
lol i just forgot a things davness 376 — 9y

Answer this question