Advertisement
iiFlamez

Untitled

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