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

Module script is not working returning different values?

Asked by 2 years ago

So im trying to make a twitter code system with datastores and stuff so i wrote this module script to manage datastores and i also used codeadder:AddCode("Release") on the command bar

local codeadder = {}
local dss = game:GetService("DataStoreService")
local store = dss:GetDataStore("@!*(*@(;p;LOL2931982912@*@2")
function codeadder.AddCode(code)
    local datatosave = {
        RedeemedBy = {}
    }

    local success, err =  pcall(function()
        store:SetAsync(code, datatosave)
    end)
    if not success then
        warn("Something went wrong")
    elseif success then
        return print("Code saved")
    end
end

function codeadder.GetCode(code)
    local dat
    local success, result =  pcall(function()
        return store:GetAsync(code)
    end)
    if success then
        return result
    end
end

function codeadder.Redeem(code, userid)
    local datatosavee = {
        RedeemedBy = {}
    }

    local success, result =  pcall(function()
        return store:GetAsync(code)
    end)
    if result ~= nil then
        for k,v in pairs(result["RedeemedBy"]) do
            if not v == userid then
                datatosavee.RedeemedBy[k] = v
            end
        end
        local thing = #datatosavee.RedeemedBy + 1
        datatosavee.RedeemedBy[thing] = userid
        local succes, errs =  pcall(function()
            return store:SetAsync(code, datatosavee)
        end)
        if succes then
            return true
        end
    end
end

function codeadder.RemoveCode(code)
    local success, results, err = pcall(function()
        return store:RemoveAsync(code)
    end)
    if success then
        print("Code has been removed L BOZO")
    end
end
function codeadder.CheckIfUsed(code, userid)
    local success,result, err =  pcall(function()
        return store:GetAsync(code)
    end)
    if result ~= nil then
        for k,v in pairs(result.RedeemedBy) do
            print(v)
            if v == userid then
                return true
            else
                return false
            end
        end
    end
end
return codeadder

I've tested this and everything worked fine until i moved the script to the new game so basically i have this script in serverscriptservice

game.ReplicatedStorage.Twitter.Redeem.OnServerEvent:Connect(function(plr, code)
    print(require(game.ServerScriptService.Codes2):GetCode(code))
end)

The above code checks if the twitter code is valid and the code i put is "Release" which i already mentioned that i added it above but the script seems to be printing nil instead of the code's information

but when i run

print(require(game.ServerScriptService.Codes2):GetCode("Release"))

on the studio command bar it returns the twitter code's information i have no idea why this is happening can anyone help?

0
what? MattVSNNL 620 — 2y

Answer this question