Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.82 KB | None | 0 0
  1. local questRemote = game.ReplicatedStorage.Remotes.QuestRemote
  2. local Datastore = require(script.Parent:WaitForChild("DataStore2"))
  3. local MarketplaceService = game:GetService("MarketplaceService")
  4.  
  5. questRemote.OnServerEvent:Connect(function(plr, called, arg1, arg2)
  6. if called == "Start Task" then
  7. local questDatastore = Datastore("Quests", plr)
  8. local quests = Datastore("Quests", plr):Get()
  9. for i,v in pairs(quests) do
  10. if i == arg1 then
  11. v.Status = "Active"
  12. end
  13. end
  14. questDatastore:Set(quests)
  15. wait(.5)
  16. elseif called == "Claim Task" then
  17. local questDatastore = Datastore("Quests", plr)
  18. local quests = Datastore("Quests", plr):Get()
  19. for i,v in pairs(quests) do
  20. if i == arg1 then
  21. if v.Status == "Completed" and v.AmountGained >= v.AmountToGain then
  22. Datastore("Money", plr):Increment(v.Cash)
  23. local VipTimer = Datastore("VipTimer", plr)
  24. quests[i] = nil
  25. local waitDatastore = Datastore("QuestTimes", plr)
  26. local waitTable = waitDatastore:Get()
  27.  
  28. local success, message = pcall(function()
  29. hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, 7914464) -- +1 Quest Pass
  30. end)
  31. local numquests = 0
  32.  
  33. for h,c in pairs(quests) do
  34. numquests = numquests + 1
  35. end
  36.  
  37. if not hasPass and VipTimer:Get() < os.time() then
  38. table.insert(waitTable, os.time() + 60*60*24)
  39. end
  40.  
  41. --Has extra mission slot but doesnt have VIP
  42. if numquests == 1 and hasPass and VipTimer:Get() < os.time() then -- and not vip, vip has a different scernio for 5 quests (What if you have pass or vip run same code?)
  43. if #waitTable ~= 3 then
  44. repeat
  45. table.insert(waitTable, os.time() + 60*60*24)
  46. until
  47. #waitTable == 3
  48. end
  49. -- if waitTable is not three then add until there is three
  50. elseif numquests == 0 and hasPass and VipTimer:Get() < os.time() then -- and not vip, vip has a different scernio for 5 quests (What if you have pass or vip run same code?)
  51. if #waitTable ~= 4 then
  52. repeat
  53. table.insert(waitTable, os.time() + 60*60*24)
  54. until
  55. #waitTable == 4
  56. end
  57. -- if waitTable is not three then add until there is three
  58. elseif numquests == 2 and hasPass and VipTimer:Get() < os.time() then
  59. if #waitTable ~= 2 then
  60. repeat
  61. table.insert(waitTable, os.time() + 60*60*24)
  62. until
  63. #waitTable == 2
  64. end
  65. -- if waitTable is not two then add until there is two
  66. elseif numquests == 3 and hasPass and VipTimer:Get() < os.time() then
  67. if #waitTable ~= 1 then
  68. repeat
  69. table.insert(waitTable, os.time() + 60*60*24)
  70. until
  71. #waitTable == 1
  72. end
  73. -- if waitTable is not one then add until there is one
  74. end
  75. --------------
  76. ---- Has VIP but not extra mission slot
  77. if numquests == 1 and not hasPass and VipTimer:Get() > os.time() then -- and not vip, vip has a different scernio for 5 quests (What if you have pass or vip run same code?)
  78. if #waitTable ~= 3 then
  79. repeat
  80. table.insert(waitTable, os.time() + 60*60*24)
  81. until
  82. #waitTable == 3
  83. end
  84. -- if waitTable is not three then add until there is three
  85. elseif numquests == 0 and not hasPass and VipTimer:Get() > os.time() then
  86. if #waitTable ~= 4 then
  87. repeat
  88. table.insert(waitTable, os.time() + 60*60*24)
  89. until
  90. #waitTable == 4
  91. end
  92. elseif numquests == 2 and not hasPass and VipTimer:Get() > os.time() then
  93. if #waitTable ~= 2 then
  94. repeat
  95. table.insert(waitTable, os.time() + 60*60*24)
  96. until
  97. #waitTable == 2
  98. end
  99. -- if waitTable is not two then add until there is two
  100. elseif numquests == 3 and not hasPass and VipTimer:Get() > os.time() then
  101. if #waitTable ~= 1 then
  102. repeat
  103. table.insert(waitTable, os.time() + 60*60*24)
  104. until
  105. #waitTable == 1
  106. end
  107. -- if waitTable is not one then add until there is one
  108. end
  109. ----------
  110. -----if they have extra mission slot and vip
  111. if numquests == 1 and hasPass and VipTimer:Get() > os.time() then -- and not vip, vip has a different scernio for 5 quests (What if you have pass or vip run same code?)
  112. if #waitTable ~= 4 then
  113. repeat
  114. table.insert(waitTable, os.time() + 60*60*24)
  115. until
  116. #waitTable == 4
  117. end
  118. -- if waitTable is not three then add until there is three
  119. elseif numquests == 0 and hasPass and VipTimer:Get() > os.time() then
  120. if #waitTable ~= 5 then
  121. repeat
  122. table.insert(waitTable, os.time() + 60*60*24)
  123. until
  124. #waitTable == 5
  125. end
  126. elseif numquests == 2 and hasPass and VipTimer:Get() > os.time() then
  127. if #waitTable ~= 3 then
  128. repeat
  129. table.insert(waitTable, os.time() + 60*60*24)
  130. until
  131. #waitTable == 3
  132. end
  133. -- if waitTable is not two then add until there is two
  134. elseif numquests == 3 and hasPass and VipTimer:Get() > os.time() then
  135. if #waitTable ~= 2 then
  136. repeat
  137. table.insert(waitTable, os.time() + 60*60*24)
  138. until
  139. #waitTable == 2
  140. end
  141. -- if waitTable is not one then add until there is one
  142. elseif numquests == 4 and hasPass and VipTimer:Get() > os.time() then
  143. if #waitTable ~= 1 then
  144. repeat
  145. table.insert(waitTable, os.time() + 60*60*24)
  146. until
  147. #waitTable == 1
  148. end
  149. -- if waitTable is not one then add until there is one
  150. end
  151. waitDatastore:Set(waitTable)
  152. end
  153. end
  154. end
  155. questDatastore:Set(quests)
  156. end
  157. end)
  158.  
  159. while true do
  160. wait(5)
  161. for i,v in pairs(game.Players:GetPlayers()) do
  162. local waitDatastore = Datastore("QuestTimes", v)
  163. local waitTable
  164. if waitDatastore:Get() then
  165. waitTable = waitDatastore:Get()
  166. for l,k in pairs(waitTable) do
  167.  
  168. if k <= os.time() then
  169. local questDatastore = Datastore("Quests", v)
  170. local quests = questDatastore:Get()
  171. local str = false
  172. local endu = false
  173. local luck = false
  174. local crowns = false
  175. local kills = false
  176. local completed = false
  177. for m, p in pairs(quests) do
  178. if p.Stat == "Strength" then
  179. str = true
  180. elseif p.Stat == "Endurance" then
  181. endu = true
  182. elseif p.Stat == "Luck" then
  183. luck = true
  184. elseif p.Stat == "Crowns" then
  185. crowns = true
  186. elseif p.Stat == "Kills" then
  187. kills = true
  188. end
  189. end
  190. repeat
  191.  
  192. local ran1 = math.random(1,5)
  193. if ran1 == 1 then
  194. stat = "str"
  195. elseif ran1 == 2 then
  196. stat = "endu"
  197. elseif ran1 == 3 then
  198. stat = "luck"
  199. elseif ran1 == 4 then
  200. stat = "kills"
  201. elseif ran1 == 5 then
  202. stat = "crowns"
  203. end
  204. if stat == "str" and not str then
  205. complete = true
  206. local ran = math.random(1,5)
  207. if ran == 1 then
  208. quests["Gain 10 Strength"] = {Status = "Not Started", Stat = "Strength", AmountGained = 0, AmountToGain = 10, Cash = 40, Crowns = 0}
  209. questDatastore:Set(quests)
  210. elseif ran == 2 then
  211. quests["Gain 50 Strength"] = {Status = "Not Started", Stat = "Strength", AmountGained = 0, AmountToGain = 50, Cash = 200, Crowns = 0}
  212. questDatastore:Set(quests)
  213. elseif ran == 3 then
  214. quests["Gain 100 Strength"] = {Status = "Not Started", Stat = "Strength", AmountGained = 0, AmountToGain = 100, Cash = 400, Crowns = 0}
  215. questDatastore:Set(quests)
  216. elseif ran == 4 then
  217. quests["Gain 175 Strength"] = {Status = "Not Started", Stat = "Strength", AmountGained = 0, AmountToGain = 175, Cash = 700, Crowns = 0}
  218. questDatastore:Set(quests)
  219. elseif ran == 5 then
  220. quests["Gain 200 Strength"] = {Status = "Not Started", Stat = "Strength", AmountGained = 0, AmountToGain = 200, Cash = 750, Crowns = 0}
  221. questDatastore:Set(quests)
  222. end
  223. elseif stat == "endu" and not endu then
  224. complete = true
  225. local ran = math.random(1,5)
  226. if ran == 1 then
  227. quests["Gain 10 Endurance"] = {Status = "Not Started", Stat = "Endurance", AmountGained = 0, AmountToGain = 10, Cash = 40, Crowns = 0}
  228. questDatastore:Set(quests)
  229. elseif ran == 2 then
  230. quests["Gain 50 Endurance"] = {Status = "Not Started", Stat = "Endurance", AmountGained = 0, AmountToGain = 50, Cash = 200, Crowns = 0}
  231. questDatastore:Set(quests)
  232. elseif ran == 3 then
  233. quests["Gain 100 Endurance"] = {Status = "Not Started", Stat = "Endurance", AmountGained = 0, AmountToGain = 100, Cash = 400, Crowns = 0}
  234. questDatastore:Set(quests)
  235. elseif ran == 4 then
  236. quests["Gain 175 Endurance"] = {Status = "Not Started", Stat = "Endurance", AmountGained = 0, AmountToGain = 175, Cash = 700, Crowns = 0}
  237. questDatastore:Set(quests)
  238. elseif ran == 5 then
  239. quests["Gain 200 Endurance"] = {Status = "Not Started", Stat = "Endurance", AmountGained = 0, AmountToGain = 200, Cash = 750, Crowns = 0}
  240. questDatastore:Set(quests)
  241. end
  242. elseif stat == "luck" and not luck then
  243. complete = true
  244. local ran = math.random(1,5)
  245. if ran == 1 then
  246. quests["Gain 10 Luck"] = {Status = "Not Started", Stat = "Luck", AmountGained = 0, AmountToGain = 10, Cash = 40, Crowns = 0}
  247. questDatastore:Set(quests)
  248. elseif ran == 2 then
  249. quests["Gain 50 Luck"] = {Status = "Not Started", Stat = "Luck", AmountGained = 0, AmountToGain = 50, Cash = 200, Crowns = 0}
  250. questDatastore:Set(quests)
  251. elseif ran == 3 then
  252. quests["Gain 100 Luck"] = {Status = "Not Started", Stat = "Luck", AmountGained = 0, AmountToGain = 100, Cash = 400, Crowns = 0}
  253. questDatastore:Set(quests)
  254. elseif ran == 4 then
  255. quests["Gain 175 Luck"] = {Status = "Not Started", Stat = "Luck", AmountGained = 0, AmountToGain = 175, Cash = 700, Crowns = 0}
  256. questDatastore:Set(quests)
  257. elseif ran == 5 then
  258. quests["Gain 200 Luck"] = {Status = "Not Started", Stat = "Luck", AmountGained = 0, AmountToGain = 200, Cash = 750, Crowns = 0}
  259. questDatastore:Set(quests)
  260. end
  261. elseif stat == "kills" and not kills then
  262. complete = true
  263. local ran = math.random(1,5)
  264. if ran == 1 then
  265. quests["Gain 10 Kills"] = {Status = "Not Started", Stat = "Kills", AmountGained = 0, AmountToGain = 10, Cash = 40, Crowns = 0}
  266. questDatastore:Set(quests)
  267. elseif ran == 2 then
  268. quests["Gain 50 Kills"] = {Status = "Not Started", Stat = "Kills", AmountGained = 0, AmountToGain = 50, Cash = 200, Crowns = 0}
  269. questDatastore:Set(quests)
  270. elseif ran == 3 then
  271. quests["Gain 100 Kills"] = {Status = "Not Started", Stat = "Kills", AmountGained = 0, AmountToGain = 100, Cash = 400, Crowns = 0}
  272. questDatastore:Set(quests)
  273. elseif ran == 4 then
  274. quests["Gain 175 Kills"] = {Status = "Not Started", Stat = "Kills", AmountGained = 0, AmountToGain = 175, Cash = 700, Crowns = 0}
  275. questDatastore:Set(quests)
  276. elseif ran == 5 then
  277. quests["Gain 200 Kills"] = {Status = "Not Started", Stat = "Kills", AmountGained = 0, AmountToGain = 200, Cash = 750, Crowns = 0}
  278. questDatastore:Set(quests)
  279. end
  280. elseif stat == "crowns" and not crowns then
  281. complete = true
  282. local ran = math.random(1,5)
  283. if ran == 1 then
  284. quests["Gain 10 Crowns"] = {Status = "Not Started", Stat = "Crowns", AmountGained = 0, AmountToGain = 10, Cash = 40, Crowns = 0}
  285. questDatastore:Set(quests)
  286. elseif ran == 2 then
  287. quests["Gain 50 Crowns"] = {Status = "Not Started", Stat = "Crowns", AmountGained = 0, AmountToGain = 50, Cash = 200, Crowns = 0}
  288. questDatastore:Set(quests)
  289. elseif ran == 3 then
  290. quests["Gain 100 Crowns"] = {Status = "Not Started", Stat = "Crowns", AmountGained = 0, AmountToGain = 100, Cash = 400, Crowns = 0}
  291. questDatastore:Set(quests)
  292. elseif ran == 4 then
  293. quests["Gain 175 Crowns"] = {Status = "Not Started", Stat = "Crowns", AmountGained = 0, AmountToGain = 175, Cash = 700, Crowns = 0}
  294. questDatastore:Set(quests)
  295. elseif ran == 5 then
  296. quests["Gain 200 Crowns"] = {Status = "Not Started", Stat = "Crowns", AmountGained = 0, AmountToGain = 200, Cash = 750, Crowns = 0}
  297. questDatastore:Set(quests)
  298. end
  299. wait(.1)
  300. end
  301. until
  302. complete == true
  303.  
  304. complete = false
  305. --waitTable[l] = nil
  306.  
  307. end
  308. end
  309. end
  310. if waitTable then
  311. for g,p in pairs(waitTable) do
  312. if p <= os.time() then
  313. waitTable[g] = nil
  314. end
  315. end
  316. waitDatastore:Set(waitTable)
  317. waitTable = nil
  318. end
  319. end
  320. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement