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

When my tool is unequipped, it won't change back to a false value? How come?

Asked by
Yeevivor4 155
9 years ago

Hello, what I'm trying to do is make an arrest tool that teleports a person to a jail if the tool handle touches him. At first, it kept putting the person in jail a lot of times, so I put a BoolValue. The BoolValue says that if the BoolValue is false, and the tool touches a person, he will get teleported and the BoolValue will become true. After 10 seconds it becomes false. The problem is that when I unequip it, the value won't go back to false anymore, rendering the tool useless.

01tool = script.Parent
02Arrest = script.Parent.Arrest
03 
04function touch(hit)
05h = hit.Parent
06g = h:findFirstChild("Humanoid")
07if Arrest.Value == false then
08Arrest.Value = true
09if (g ~= nil) then
10h:MoveTo(game.workspace.Jail.Position)
11wait(10)
12Arrest.Value = false
13end
14end
15end
View all 21 lines...

1 answer

Log in to vote
1
Answered by 9 years ago

Problem: BoolValue Arrest doesn't turn off when tool goes unequipped. Cause: There is nothing in the code to tell the boolean to turn off when the tool is unequipped. You only made it turn off after 10 seconds. Solution: Use the Unequipped event to turn it off.

1tool.Unequipped:connect(
2    function()
3        Arrest.Value = false
4    end
5)

Other things to note: -Lack of use of local variables to optimize the script (see this: -Instead of using (variable ~= nil) you can use variable standing alone because it still works. Because if it is true then it automatically returns the if statement as true. -Indent your scripts. -Look up "Debounce" on the wiki if you want to use cooldown instead of unequip.

Ad

Answer this question