Error: "attempt to call a Instance value"

I have a system where you can pick up an item (Chairs) using a proximity prompt inside of it, When the item is picked up I set the parent of the proximity prompt to nil, so the prompt disappears. I also want to remove all other proximity prompts for other items, so the prompts don’t get in the way and also so you can’t pick more than one thing up etc. I only want the prompts to be removed for the player that picks an item up of course so the way I have gone about it is…

LocalPlayer:GetAttributeChangedSignal("Holding"):Connect(function()
	if LocalPlayer:GetAttribute("Holding") == "idle" then
		local prompt, chair = HoldingFunction:InvokeServer()
		prompt.Parent = chair
	end
end)

^ChairClient: A local script under StarterPlayerScripts^

--Functions
local function getPrompts(player, prompt, chair)
	return prompt, chair
end

*skip ahead in the code

function PickUp:Init()
	--Set the prompt up
	self.Prompt = self:CreatePrompt()
	HoldingFunction.OnServerInvoke = getPrompts(self.Prompt, self.Chair)
	self.Prompt.Triggered:Connect(function(...)
		if not self.Liftable then return else self.Chair:SetAttribute("Liftable", false) end
		self:Press(...)
	end)
end

^PickUp: A module script inside ServerScriptService (It uses OOP)

The main problem I am having is that when the game is played, inside of ChairClient, the local script, it returns an error: “attempt to call a Instance value”

Which occurs on line 27:

local prompt, chair = HoldingFunction:InvokeServer()

From what I have seen most people with this error attempted to call brackets like you would with a function on something that is not a function, in my case I do not think that is what is happening, I don’t think it is a syntax error either. I would like help with this, thank you in advance!

TL;DR

ModuleScript:

local function getPrompts(player, prompt, chair)
	return prompt, chair
end


HoldingFunction.OnServerInvoke = getPrompts(self.Prompt, self.Chair)

LocalScript:

local prompt, chair = HoldingFunction:InvokeServer()

Local script errors: “attempt to call a Instance value”

This is interesting. The error you got from the localscript does not actually mean the localscript is the source of the issue. What it’s actually doing is just relaying the error that the server got back to the client. It’s the server script with the .OnServerInvoke that’s causing the error.

I’ve tested it myself here, the server reports the error first and then relays it to the client.

So what’s the issue? It’s how you bound the OnServerInvoke function:

What’s wrong here? You are calling getPrompts() and giving the result to .OnServerInvoke. The function getPrompts returns two values (a tuple), but only the first one is used because you are assigning it to a single data container (.OnServerInvoke). The first value in the tuple is just prompt, which is self.Chair. What all this sums up to is you effectively doing:

HoldingFunction.OnServerInvoke = self.Chair

The error message you got is “attempt to call a Instance value”, which means the API mistook an Instance for a function and tried calling it as if it was a function. self.Chair is an instance, which is definitely not a function.

Perhaps what you were meant to be doing is passing the function itself to .OnServerInvoke.

local function getPrompts(player, prompt, chair)
	return prompt, chair
end

HoldingFunction.OnServerInvoke = getPrompts
1 Like

No more errors, thanks a lot. :grinning: :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.