Advertisement
iiFlamez

Untitled

Mar 24th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. --Start of CreateButton
  2. function CreateDict(Table)
  3. local PlayerF = {}
  4. for i,v in next, Table do
  5. if not v:IsA("Folder") then
  6. PlayerF[v.Name] = v.Value
  7. end
  8. end
  9. return PlayerF
  10. end
  11.  
  12.  
  13. function Count(Table)
  14. local Count = 0;
  15. for i,v in next, Table do
  16. Count = Count+1
  17. end
  18. return Count;
  19. end
  20.  
  21. function Check(PFolder,Requirments)
  22. local Count = 0;
  23. for i,v in next, Requirments do
  24. if tonumber(PFolder[i]) ~= nil and PFolder[i] and tonumber(PFolder[i]) >= tonumber(v) then
  25. Count = Count+1;
  26. elseif tostring(PFolder[i])~= nil and PFolder[i] and tostring(PFolder[i]) == tostring(v) then
  27. Count = Count+1;
  28. end
  29. end
  30. return Count;
  31. end
  32.  
  33. --[[Button must be the button instance not the click detector,
  34. Requirements must be the dictionary of Requirements
  35. Stat is the Stat to be indexed if they meet the requirement
  36. Value is what the stats value should be set to if they meet the requirement
  37. --]]
  38.  
  39. function CreateClick(Button,Requirements,Stat,Value)
  40. local Original = Button.Name;
  41. local Debounce = false;
  42. Button.Head.ClickDetector.MouseClick:connect(function(PLAYER)
  43. if Debounce then
  44. return
  45. end
  46. local PFolder = game:GetService("ServerStorage").PlayerFolders:WaitForChild(tostring(PLAYER))
  47. local PFolderDict = CreateDict(PFolder:GetChildren());
  48. if Count(Requirements) ~= Check(PFolderDict,Requirements) then
  49. Button.Name = "Improper requirements";
  50. Debounce = true;
  51. wait(2);
  52. Debounce = false;
  53. Button.Name = Original;
  54. elseif Count(Requirements) == Check(PFolderDict,Requirements) then
  55. Debounce = true;
  56. if Requirements["Gold"] then
  57. PFolder.Gold.Value = PFolder.Gold.Value - Requirements["Gold"];
  58. end
  59. if Requirements["Bounty"] then
  60. PFolder.Bounty.Value = PFolder.Bounty.Value - (Requirements["Bounty"]/2);
  61. end
  62. PFolder[Stat].Value = Value;
  63. Button.Name = "Success!"
  64. wait(2);
  65. Debounce = false;
  66. Button.Name = Original;
  67. end
  68. end)
  69. end
  70.  
  71. --End of CreateClick function
  72.  
  73. --This is an example of how it should look like
  74. local CyborgReq3 = {["LVL"] = 15, ["Gold"] = 40000,["Race"] = "Cyborg",["CyborgUpgrade2"] = true,["CyborgUpgrade3"] = false}
  75. CreateClick(workspace["Cyborg Upgrade3 [40k Beli] [Level 15]"],CyborgReq3,"CyborgUpgrade3",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement