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
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