Code main fuction calls error. Possible fix?
Asked by
5 years ago Edited 5 years ago
Ok so I'm making a code gui. It was working until I introduced a code that has a limit to it. Now that there is a limit it just breaks.
The error im getting is :
1 | ServerScriptService.Codes: 12 : attempt to index local 'CheckUsage' (a nil value) |
3 | Script 'ServerScriptService.Codes' , Line 12 - upvalue CheckLimited |
4 | Script 'ServerScriptService.Codes' , Line 38 |
My code for reference:
01 | local ActiveCodes = game.ServerStorage.ActiveCodes |
03 | local Remote = game.ReplicatedStorage.Code |
05 | local Data = game:GetService( "DataStoreService" ) |
06 | local Getcode = Data:GetDataStore( "UsedCode" ) |
09 | local function CheckLimited(CodeObj) |
10 | local CheckUsage = Getcode:GetAsync( "GlobalUseOf" .. CodeObj.Name) |
11 | if CheckUsage = = nil then |
12 | CheckUsage:SetAsync( "GlobalUseOf" .. CodeObj.Name, 0 ) |
19 | local function SaveLimited(CodeObj) |
20 | local GetUsage = Getcode:GetAsync( "GlobalUseOf" .. CodeObj.Name) |
21 | if GetUsage ~ = nil then |
22 | GetUsage:SetAsync( "GlobalUseOf" .. CodeObj.Name, GetUsage + 1 ) |
26 | local function OnCode(Plr, Code) |
27 | local Get = Getcode:GetAsync(Plr.UserId .. Code) |
29 | local Stats = Plr:WaitForChild( "leaderstats" ) |
30 | local CodeObj = game.ServerStorage.ActiveCodes:FindFirstChild(Code) |
32 | if not CodeObj then return "No active code called " .. Code end |
34 | local RequiredStat = Stats:WaitForChild(CodeObj.Stat.Value) |
35 | local CodeAmmount = CodeObj.Value |
37 | if CodeObj:FindFirstChild( "Limit" ) then |
38 | if CheckLimited(CodeObj) < 10 then |
40 | if RequiredStat.Name = = "Shards" then |
41 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats.Rebirths.Value + 1 )) |
42 | elseif RequiredStat.Name = = "Rebirths" then |
43 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Super Rebirths" ] .Value + 1 )) |
44 | elseif RequiredStat.Name = = "Super Rebirths" then |
45 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Ultra Rebirths" ] .Value + 1 )) |
46 | elseif RequiredStat.Name = = "Ultra Rebirths" then |
47 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Omega Rebirths" ] .Value + 1 )) |
48 | elseif RequiredStat.Name = = "Omega Rebirths" then |
49 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Master Rebirths" ] .Value + 1 )) |
51 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount) |
54 | Getcode:SetAsync(Plr.UserId .. Code, true ) |
56 | return "Code already Used" |
59 | return "Code Limit Reached" |
62 | if RequiredStat.Name = = "Shards" then |
63 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats.Rebirths.Value + 1 )) |
64 | elseif RequiredStat.Name = = "Rebirths" then |
65 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Super Rebirths" ] .Value + 1 )) |
66 | elseif RequiredStat.Name = = "Super Rebirths" then |
67 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Ultra Rebirths" ] .Value + 1 )) |
68 | elseif RequiredStat.Name = = "Ultra Rebirths" then |
69 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Omega Rebirths" ] .Value + 1 )) |
70 | elseif RequiredStat.Name = = "Omega Rebirths" then |
71 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount * (Stats [ "Master Rebirths" ] .Value + 1 )) |
73 | RequiredStat.Value = RequiredStat.Value + (CodeAmmount) |
75 | Getcode:SetAsync(Plr.UserId .. Code, true ) |
79 | Remote.OnServerInvoke = OnCode |
Hope someone can help me!