Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Help] Not Working Why?

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

✓ Accepted answer

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

1 comment

0

It is giving out the information weather it true or false but the problem is, it didnt add my currency. Why?

This discussion is preserved as it was. New answers, comments, and votes are closed.