Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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 :

1ServerScriptService.Codes:12: attempt to index local 'CheckUsage' (a nil value)
2Stack Begin
3Script 'ServerScriptService.Codes', Line 12 - upvalue CheckLimited
4Script 'ServerScriptService.Codes', Line 38
5Stack End

My code for reference:

01local ActiveCodes = game.ServerStorage.ActiveCodes
02 
03local Remote = game.ReplicatedStorage.Code
04 
05local Data = game:GetService("DataStoreService")
06local Getcode = Data:GetDataStore("UsedCode")
07--local Get = Getcode:GetAsync(Plr.UserId .. Code)
08 
09local function CheckLimited(CodeObj)
10    local CheckUsage = Getcode:GetAsync("GlobalUseOf" .. CodeObj.Name)
11    if CheckUsage == nil then
12        CheckUsage:SetAsync("GlobalUseOf" .. CodeObj.Name, 0)
13        return 0
14    else
15        return CheckUsage
View all 79 lines...

Hope someone can help me!

0
I think you should check line 12 again....idk Nguyenlegiahung 1091 — 5y
0
Ye i just realised thanks MrCatDoggo 213 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Your if statement on line 11 is exactly the wrong way around:

if CheckUsage == nil then

You have to use ~= to check if CheckUsage is not nil

0
Nope I'm checking to see if its nil so I can set it to 0. MrCatDoggo 213 — 5y
0
Wait i just realsied an error ive had lol MrCatDoggo 213 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Turns out i didn't recheck so sorry to anyone who took the time.

Answer this question