Attempt to Call an Instance Value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

So I’m trying to improve my old value saving script w/ datastore 2 and I’m following this youtube tutorial, the script works fine until line 49 where I get an error reading:

ServerScriptService.Currency.Leaderstats2:49: attempt to call a Instance value

Here’s the full script I made

local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey", "Level", "XP")

local DefaultRank = 0
local DefaultXP = 0
local DefaultGold = 0

local xpToLevelUp = function(Rank)
	return (((Rank.Value*(Rank.Value - 1))/15) * 100) + 100
end

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local GoldValue = Instance.new("IntValue", leaderstats)
	GoldValue.Name = "Gold"
	
	local UnbankedValue = Instance.new("IntValue", leaderstats)
	UnbankedValue.Name = "UnbankedGold"
	
	local RankValue = Instance.new("IntValue", leaderstats)
	RankValue.Name = "Rank"
	
	local XPValue = Instance.new("IntValue", leaderstats)
	XPValue.Name = "XP"
	
	local XPMaxValue = Instance.new("IntValue", leaderstats)
	XPMaxValue.Name = "XPMax"
	
	-- Get datastores
	
	local GoldStore = DataStore2("Gold", player)
	local UnbankedStore = DataStore2("Unbanked", player)
	local RankStore = DataStore2("Rank", player)
	local XPStore = DataStore2("XP", player)
	
	-- Functions when Rank + XP + Gold Change
	
	local function UpdateGold(Gold)
		player.leaderstats.Gold.Value = Gold
	end
	
	local function UpdateRank(Rank)
		player.leaderstats.Rank.Value = Rank
	end
	
	local function UpdateXP(XP)
		if XP >= XPMaxValue(XPStore:Get(DefaultRank)) then -- [LINE 49 - ServerScriptService.Currency.Leaderstats2:49: attempt to call a Instance value]
			XPStore:Increment(xpToLevelUp(RankStore:Get(DefaultRank)) * -1)
			RankStore:Increment(1)
		else
			player.leaderstats.XP.Value = XP
		end
	end
	
	
	-- Call functions at once
	UpdateRank(RankStore:Get(DefaultRank))
	UpdateXP(XPStore:Get(DefaultXP))
	UpdateGold(GoldStore:Get(DefaultGold))
	
	-- Call functions again on updates
	
	RankStore:OnUpdate(UpdateRank)
	XPStore:OnUpdate(UpdateXP)
	GoldStore:OnUpdate(UpdateGold)
end)
1 Like

Did you by any chance mean to multiply? You can’t call instances, as the exception message tells you, or what were you trying to do?

2 Likes

XPMaxValue is an Instance, not a function

1 Like

You’ve used the Instance XPMaxValue as a function. You’ve defined it as this.

local XPMaxValue = Instance.new("IntValue", leaderstats)
XPMaxValue.Name = "XPMax"

Yet you clearly use it as a function here:

if XP >= XPMaxValue(XPStore:Get(DefaultRank)) then -- [LINE 49 - ServerScriptService.Currency.Leaderstats2:49: attempt to call a Instance value]

You might want to change your code to something like this:

if XP >= xpToLevelUp(XPStore:Get(DefaultRank)) then

Continuing on, in the xpToLevelUp function you’ve defined:

local xpToLevelUp = function(Rank)
	return (((Rank.Value*(Rank.Value - 1))/15) * 100) + 100
end

You don’t need .Value statements here if you pass a number into the function.

1 Like

Probably should be following the tutorial more closely next time then huh :confused: