Attempting to Index a nil value

Had my code working properly until I tried to mess with my rankStore values, Line 58 is where the error occurs

The error code says " ServerScriptService.GameDataStore:58: attempt to call a nil value

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")

local DataStore2 = require(game.ServerScriptService.DataStore2)
local defaultValue = 0
local defaultRank = 1

DataStore2.Combine("Tester1", "clicks", "gems", "eggs", "rank")

Players.PlayerAdded:Connect(function(player)
	local clicksStore = DataStore2("clicks", player)
	local gemsStore = DataStore2("gems", player)
	local eggsStore = DataStore2("eggs", player)
	local rankStore = DataStore2("rank", player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local clicks = Instance.new("IntValue",leaderstats)
	clicks.Name = "Clicks"
	clicks.Value = clicksStore:Get(defaultValue) -- fetches the value for the first time
	
	local gems = Instance.new("IntValue",leaderstats)
	gems.Name = "Gems"
	gems.Value = gemsStore:Get(defaultValue)
	
	local eggs = Instance.new("IntValue",leaderstats)
	eggs.Name = "Eggs"
	gems.Value = eggsStore:Get(defaultValue)
	
	local rank = Instance.new("IntValue",player)
	rank.Name = "RankMulti"
	rank.Value = rankStore:Get(defaultRank)
	
	-- these functions update the value objects
	local function clicksUpdate(updatedValue)
		clicks.Value = updatedValue
	end
	
	local function gemsUpdate(updatedValue)
		gems.Value = updatedValue
	end
	
	local function eggsUpdate(updatedValue)
		eggs.Value = updatedValue
	end
	
	local function rankUpdate(updatedValue)
		rank.Value = updatedValue
	end
	
	-- keeping all the connections at the bottom makes it easier to read
	clicksStore:OnUpdate(clicksUpdate)
	gemsStore:OnUpdate(gemsUpdate)
	eggsStore:OnUpdate(eggsUpdate)
	rankStore:onUpdate(rankUpdate)  -- Line 58 (error is here)
	
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClickMe = game.ReplicatedStorage:WaitForChild("ClickMe")

local function onClickMe(player)
	local rankStore = DataStore2("rank", player)
	local clicksStore = DataStore2("clicks", player)
	local defaultClick = 1 --Define the standard increment per click
	local multiplier = 1
	
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 1111111) then
		multiplier = 2
		print("hi")
	end
		clicksStore:Increment(defaultClick * rankStore:Get() * multiplier, 0) -- the 0 here is the default value for the clickStore
		print("hello")
	end

local RankUp1 = game.ReplicatedStorage:WaitForChild("RankUp1")

local function OnRankUp1(player)
	local rankStore = DataStore2("rank", player)
	
		rankStore:Increment(1)
end

ClickMe.OnServerEvent:Connect(onClickMe)
RankUp1.OnServerEvent:Connect(OnRankUp1)
1 Like

It’s supposed to be OnUpdate, not onUpdate. It’s just a simple spelling error really.

1 Like

LOL i am an idiot, thankyou sir!

1 Like