Existence_YT

[MakingASimulator] ClickHandler

May 26th, 2020
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. local CollectionService = game:GetService("CollectionService")
  2. local Connections = {}
  3.  
  4. function removeConnection(obj)
  5.     if Connections[obj] then
  6.         Connections[obj]:disconnect()
  7.         Connections[obj] = nil
  8.     end
  9. end
  10.  
  11. for i, v in pairs(workspace.Clickers:GetDescendants()) do
  12.     if v.Name == "Click" then
  13.         CollectionService:AddTag(v, "Clicker")
  14.     end
  15. end
  16.  
  17. for i, v in pairs(CollectionService:GetTagged("Clicker")) do
  18.     v.Parent.UI.Frame.Val.Text = tostring(v:WaitForChild("ClicksLeft").Value)
  19.     Connections[v] = v.MouseClick:Connect(function(plr)
  20.         if v.ClicksLeft.Value >= 1 and v:WaitForChild("Enabled").Value == true then
  21.             plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + (1 + (1*plr.leaderstats.Multiplier.Value)) --math...
  22.             v.ClicksLeft.Value = v.ClicksLeft.Value - 1
  23.             v.Parent.UI.Frame.Val.Text = tostring(v.ClicksLeft.Value)
  24.             if v.ClicksLeft.Value <= 0 then
  25.                 v.Enabled.Value = false
  26.                 spawn(function()
  27.                     for i = 1, 10, 1 do
  28.                         wait(.5)
  29.                         v.ClicksLeft.Value = v.ClicksLeft.Value + 1
  30.                         v.Parent.UI.Frame.Val.Text = tostring(v.ClicksLeft.Value)
  31.                     end
  32.                     if v.ClicksLeft.Value == 10 then
  33.                         v.Enabled.Value = true
  34.                     end
  35.                 end)
  36.             end
  37.         end
  38.     end)
  39. end
Advertisement
Add Comment
Please, Sign In to add comment