Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my RemoteFunction giving me an error saying, "attempt to call a number value"?

I am currently learning how RemoteEvents, and RemoteFunctions work, and in my game, I want to send an IntValue from the server to a specific client, and update that player's MoneyGui to show the sent IntValue. However, I keep getting an error in the output saying, "attempt to call a number value". Does anyone know why?

Also, I understand the difference between RemoteFunctions and RemoteEvents. RemoteFunctions can send and receive information two ways, while RemoteEvents can only send and receive information one way. I would use a RemoteEvent, except I don't know how to access a value sent from a RemoteEvent.

Here is the code.

Server Script

script.Parent.Touched:Connect(function(hit)
local sendValue = game.ReplicatedStorage.SendValue
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local storedValue = script.Parent.Parent.storedValue 
	
	local function returnValue()
		return storedValue.Value
	end
		
	if player then
		sendValue.OnServerInvoke = returnValue()
	end
end)

Client Script (Inside of a textLabel)

while wait() do
local getValue = game:GetService("ReplicatedStorage"):FindFirstChild("SendValue"):InvokeServer()

	script.Parent.Text = tostring(getValue)
end

I hope this made sense.

Thanks in advance!

1 answer

✓ Accepted answer

The reason it says "Attempt To Call A Number Value" is because of the returnValue function, when we say return it means send back information, so it turns out to be this (from what i know)

sendValue.OnServerInvoke = storedValue.Value

but that causes an error, so we need to make it all in one!

-- {{ SERVER }} --

script.Parent.Touched:Connect(function(hit)
	local sendValue = game.ReplicatedStorage.SendValue
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local storedValue = script.Parent.Parent.storedValue 

	if player then
        sendValue.OnServerInvoke = function()
		return storedValue.Value
	end
    end
end)

-- [[ CLIENT ]] --

while wait(1) do
	local getValue = game:GetService("ReplicatedStorage"):.SendValue:InvokeServer()
	script.Parent.Text = tostring(getValue)
end

now the reason i put wait(1) in just because it seemed like you kept invoking the remote function a lot lol

-- Hope It Helped :)

-Kriscross102

5 comments

0

It works! Thanks man. I have been trying to figure this out all day.

0

Just curious, if I used a RemoteEvent, and Fired to the Client an IntVale, how would I access the value I fired, from the local script? I am still learning how Events work, and I think it would be easier to simply Fire the Value to the client each time the part is touched. Thanks again.

0

add a parameter called plr, and in that send the players name, then in the server script fire to the client with the player you sent, its a bit of a hacky way

0

You don't need to make returnValue an anonymous function, it could stay named as he wanted it. It's just a matter of assigning the function reference, not calling it. i.e. sendValue.OnServerInvoke = returnValue() should have been sendValue.OnServerInvoke = returnValue

0

...but, I think there are bigger problems with this code, in terms of how it's meant to work for multiple players. Assigning a remoteFunction's OnServerInvoke more than once is unusual, and almost certainly not what you want here.

This discussion is preserved as it was. New answers, comments, and votes are closed.