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

Should this code work more than once?

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

debounce=false
script.Parent.Touched:connect(function(hit)
	print(hit.Name)
	plr=game.Players:GetPlayerFromCharacter(hit.Parent)
		
		
	if plr then
		print(plr.Name)
		if debounce==true then
			
		
elseif debounce==false then	
		debounce=true
	local PointsService = Game:GetService("PointsService")
 
	local pointsToAward = PointsService:GetAwardablePoints()
	

	
	if ( pointsToAward < 0 ) then
		print("No Points left")	
	elseif ( pointsToAward > 0 ) then
		
		pcall(function()
			if Game:GetService("GamePassService"):PlayerHasPass(plr, 160676880) then 
			PointsService:AwardPoints(plr.userId, 50)
			plr.PlayerGui.CollectSound:Play()
			else 
				PointsService:AwardPoints(plr.userId, 25)
			plr.PlayerGui.CollectSound:Play()
			wait(5)
	debounce=false
	end
		end)
	end

 
-- Bind function to when points are successfully awarded
	
	end
	end
end)


7 comments

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.

0

Yeah, what is weird is, in my game, people have been complaining that it stops working

0

Perhaps you're running out of Player Points to distribute?

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.

0

WAIT, does it matter if I say "plr=stuff" or "local plr=stuff"

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.
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

1 answer

debounce=false
script.Parent.Touched:connect(function(hit)
	if then
		if debounce==true then
		elseif debounce==false then 
	        	debounce=true
			if  then
			elseif then
	        		pcall(function()
	            			if then 
	            			else
    						debounce=false
	    				end
	        		end)
	    		end
		end
	end
end)

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:

...
	debounce=true
	if ... then
		...
	end
	debounce=false
...

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