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

How do you make a click detector infinite?

I've recently made a cup clicker, so if you click a cup, it'll give you one, the only issue here is that if you try to get multiple cups by clicking multiple times, it won't.

If you're wondering about the script, here it is:

local tool = game.ServerStorage.Cup local klone = tool:clone() script.Parent.ClickDetector.MouseClick:connect (function(plr) if klone.Parent ~= plr.Backpack then klone.Parent = plr.Backpack else end end)

2 answers

local tool = game.ServerStorage.Cup 
local klone = tool:clone() 
script.Parent.ClickDetector.MouseClick:connect (function(plr) 
--if klone.Parent ~= plr.Backpack then klone.Parent = plr.Backpack --Says tool will clone to backpack if it doesnt already exist. So change the not sign to an equal sign so to change it. You dont need an if statement.
klone.Parent = plr.Backpack
 end 
end)

1 comment

0

So yeah now this should give you multiple cups if you click on it

What you did wrong is you defined the "klone" variable before the function runs. This means that there is only 1 instance that the script is allowed to give to the player. To fix this, simply move the tool variable inside of your function. The fixed script would look like this:

local tool = game.ServerStorage:WaitForChild("Cup")		 
 script.Parent.ClickDetector.MouseClick:connect (function(plr)
	local klone = tool:clone() -- makes a new clone every click so you have more than one.
 	if klone.Parent ~= plr.Backpack then
		klone.Parent = plr.Backpack 
	else 

	end 
end)

Hope I helped!

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