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

[Help] Not Working Why?

Asked by 4 years ago
Edited 4 years ago

Remote Function

Everything have been fixed without any error. But then problems is the currency doesnt add into players currency

--Client
local TextBox = script.Parent.TextBox
local Button = script.Parent.RedeemButton

Button.MouseButton1Click:Connect(function()
    local Code = TextBox.Text
    local redeem = game.ReplicatedStorage.RemoteFuntion:InvokeServer(Code)
    if redeem == true then
        TextBox.Text = " "
        TextBox.PlaceholderText = "Success"
        wait(0.5)
        TextBox.PlaceholderText = "Text Here"
    else
        TextBox.Text = " "
        TextBox.PlaceholderText = "Invalid"
        wait(0.5)
        TextBox.PlaceholderText = "Text Here"
    end
end)

Why it doesnt work?

--Server

local DataService = game:GetService("DataStoreService")

local ListCode = {
    TestCode = {"Money", 2500},
    Code2020 = {"Money", 2020}
}

game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(plr, Code)
    local players = game.Players:FindFirstChild(plr.Name)
    local CodeStore = DataService:GetDataStore("CodeStore" .. Code)
    local plrRedeem = CodeStore:GetAsync(players.UserId)
    if ListCode[Code] and not plrRedeem then
        local statsName = ListCode[Code][1]
        local amtValue = ListCode[Code][2]
        local statsValue = players.leaderstats[statsName].Value
        statsValue = statsValue + amtValue
        CodeStore:SetAsync(players.UserId, true)
        return true
    else
        return false
    end
end

1 answer

Log in to vote
1
Answered by 4 years ago

On line 16, with the code

local statsValue = plr.leaderstats[statsName]

you're retrieving the instance. You want the value, so you should update it to:

local statsValue = plr.leaderstats[statsName].Value
0
It is giving out the information weather it true or false but the problem is, it didnt add my currency. Why? LikuLiku75 -1 — 4y
Ad

Answer this question