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

How do you make a click detector infinite?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
So yeah now this should give you multiple cups if you click on it voidofdeathfire 148 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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!

Answer this question