Need Help with Game Code Script!

I’m trying to make a system where a player inputs a code into a text box, and when they hit a button a local script sends that Code to the server using a remote function. Then the Server determines if its a valid code and if it hasn’t been redeemed and gives the player the amount of “Taps” assigned to the code if both values are met otherwise returning false. However, when I tested my scripts in game, no matter what code I entered, the script would always error saying “(Code I entered)” is not a valid member of GlobalDataStore “DataStoreService.codesStore”. Any idea whats wrong. Im assuming its something to do with the function below

local Codes = {
	VizorPlays = {200},
	NewPlayer1 = {100},
	xX0124Xx = {70},
}

game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(Player, Code)
	local codesStore = DSS:GetDataStore("codesStore" .. Code)
	local PlayerRedeemedCode = codesStore:GetAsync(Player.UserId)
	
	if codesStore[Code] and not PlayerRedeemedCode then
		Player.leaderstats.Taps.Value = Player.leaderstats.Taps.Value +codesStore[Code][1]
		
		codesStore:SetAsync(Player.UserId, true)
		
		return true
	else
		return false
	end
end
2 Likes

GetDataStore returns a DataStore, not the DataStore’s content

I was wondering if thats the problem but even when I took out …Code it was still giving the same error.

I think you meant to do this for your code:

local Codes = {
	VizorPlays = {200},
	NewPlayer1 = {100},
	xX0124Xx = {70},
}

game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(Player, Code)
	local codesStore = DSS:GetDataStore("codesStore" .. Code)
	local PlayerRedeemedCode = codesStore:GetAsync(Player.UserId)
	
    -- use the 'codes' table
	if Codes[Code] and not PlayerRedeemedCode then
		Player.leaderstats.Taps.Value += Codes[Code][1]
		
		codesStore:SetAsync(Player.UserId, true)
		
		return true
	else
		return false
	end
end
1 Like

Ya lol, that was it. I don’t know how I looked over that. Thank you for pointing that out.

1 Like