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

Two scripts, a money script and GUI cloning script, only working once? ggargagrgrgrae

The jist is that every time a player hit this block, one script increases a value in their leaderstats and the other clones and puts a GUI in their playergui (the gui just shows '+10', for the amnt gained)

However, it will only do this once. I am stumped. Why?

GUI cloning script:

local debounce = false



function getPlayer(humanoid) 

	local players = game.Players:children() 

for i = 1, #players do 

	if players[i].Character.Humanoid == humanoid then return players[i] end 

end 

	return nil 

end 



function onTouch(part) 



	local human = part.Parent:findFirstChild("Humanoid") 

if (human ~= nil) and debounce == false then



	debounce = true



	local player = getPlayer(human) 



	if (player == nil) then return end 



	user = game.Players:findFirstChild(human.Parent.Name)

	local gui= script.Parent.Plus:clone()
	gui.Parent = player.PlayerGui
	gui.Frame.Amount.Find.Disabled = false






	wait(2)

else

	wait(2)

	debounce = false

end

end





script.Parent.Touched:connect(onTouch) 

Cash adding script:

debounce = false

function onTouched(part)
	
	if debounce == false then
		
	local h = part.Parent:findFirstChild("Humanoid")
	
	
	if (h~=nil) then
		
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		
		if (thisplr~=nil) then
			
			local stats = thisplr:findFirstChild("leaderstats")
			
			if (stats~=nil) then
				
				debounce = true
				
				local cash = stats:findFirstChild("SpeedCoin")
				
				if (cash~=nil) then
					
					cash.Value = cash.Value+ 10
					wait(0.3)
					debounce = false
				end
			end
		end
	end
	end
	end

script.Parent.Touched:connect(onTouched)

7 comments

0

The title spam was because it would not let me post my question, saying it was not concise enough. Sorry

0

It only adds cash once, or only shows the GUI once?

0

ggargagrgrgrae

0

Both, Dinoz.

0

Are they both server scripts? Why are they in seperate scripts?

0

they are both server scripts. and idk, i just never thought to combine them. never had a problem with the separately till i put them in the same brick

0

Merge them, clean up the indentation, get rid of all the useless whitspace.

1 answer

✓ Accepted answer

The problem is that you included the debounce = false before the end. In this case, if (human ~= nil) and debounce == false then the debounce = false will not run because you've put it after the else statement. To make the script work, you just need to move the debounce = false under one end statement and it will set debounce to false even if (human ~= nil) and debounce == false

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