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

Should this code work more than once?

Asked by 10 years ago

I have been getting word that this works only once, but it seems that it should work multiple times.

01debounce=false
02script.Parent.Touched:connect(function(hit)
03    print(hit.Name)
04    plr=game.Players:GetPlayerFromCharacter(hit.Parent)
05 
06 
07    if plr then
08        print(plr.Name)
09        if debounce==true then
10 
11 
12elseif debounce==false then
13        debounce=true
14    local PointsService = Game:GetService("PointsService")
15 
View all 42 lines...
0
It looks fine to me. Have you tested it? By the way, your indentation could use some work. It's very difficult to read. MrFlimsy 345 — 10y
0
Yeah, what is weird is, in my game, people have been complaining that it stops working Tempestatem 884 — 10y
0
Perhaps you're running out of Player Points to distribute? MrFlimsy 345 — 10y
0
No, I already thought if that, it isnt that. I am almost considering it could be a stack end in the part of it, causing it to work once? I thought maybe the CollectSound isnt in PlayerGui. Tempestatem 884 — 10y
View all comments (3 more)
0
WAIT, does it matter if I say "plr=stuff" or "local plr=stuff" Tempestatem 884 — 10y
0
1) pointsToAward <= to 0, not just "<". 2) You're not checking whether the game has 50 or 25 points to award, so it should really be pointsToAward <= 24 or 49, depending on the pass status. GoldenPhysics 474 — 10y
0
The game has not run out of points. Its nothing to do with that. In game output tells me that "plr" is a nil value Tempestatem 884 — 10y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago
01debounce=false
02script.Parent.Touched:connect(function(hit)
03    if then
04        if debounce==true then
05        elseif debounce==false then
06                debounce=true
07            if  then
08            elseif then
09                    pcall(function()
10                            if then
11                            else
12                            debounce=false
13                        end
14                    end)
15                end
16        end
17    end
18end)

After removing the actual content of the script, you can clearly see that debounce will not be set back to false unless a certain set of criterion is matched every time. If for one time it isn't, it never works again. You should be setting debounce to false in the same block that it's being set to true. That would look more like this:

1...
2    debounce=true
3    if ... then
4        ...
5    end
6    debounce=false
7...
Ad

Answer this question