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!
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