Need Help Fixing DataService Issue

  1. What do you want to achieve? I’m trying to set up a twitter code redeeming UI that gives the player x amount of points for redeeming each code.

  2. What is the issue? I keep being received with the following error:

ServerScriptService.Server.Services.DataService:75: attempt to index nil with 'points'  
  1. What solutions have you tried so far? Scripting isn’t my specialty, so I haven’t got much knowledge as to what to do here.

Here are the excerpts of what I believe is the relevant code:

The Code that is supposed to distribute the points (but with no success):

game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(Player, Code, player)
	local TwitterCodeStore = DataStoreService:GetDataStore("TwitterCodesStore2" .. Code)
	local PlayerRedeemedCode = TwitterCodeStore:GetAsync(Player.UserId)

	if TwitterCodes[Code] and not PlayerRedeemedCode then
		print("redeemed!")
		local AmountToGivePlayer = TwitterCodes[Code][2]
		Knit.Services.DataService:addPoints(player, AmountToGivePlayer)
		TwitterCodeStore:SetAsync(Player.UserId, true)
		
				return true
			else
				return false
	end
end

The Code that handles the redeeming system (and returns the abovementioned error):

RedeemButton.MouseButton1Click:Connect(function()
	local Code = CodeBox.Text
	local Redeemed = game.ReplicatedStorage.RedeemCode:InvokeServer(Code)
end)

The line that invokes the server is returning the error

But yeah would greatly appreciate if anybody could help me out with this issue. I’m happy to share more of the code if necessary but didn’t want to down right send the whole scripts bc of devforum rules.

Thanks :slight_smile:

1 Like

Change this line

Knit.Services.DataService:addPoints(player, AmountToGivePlayer)

To

Knit.Services.DataService:addPoints(Player, AmountToGivePlayer)

I don’t know why you have a player as 3rd argument. That’s nil and you should probably remove it.

1 Like

Man don’t you love it when a lack of capitalization can bring your entire script to heel lmao. Thanks man I appreciate the help. What did you mean by remove the player as a 3rd argument though, like from where?

1 Like

From here. The 3rd argument is nil since your client only passes the Code.

1 Like

Yeah all good I spotted it right after I replied to you sorry lol. Thanks again man

1 Like