RemoteEvent attempt to call a Instance value

this script receives a signal when a player buys an item from a button
and will update the amount of money after the player bought an item.

The line I’m having a problem with is line 14
I’m trying to send a number to the client side but got this error:
attempt to call an Instance value
so instead I changed from sending through remote event directly to sending values through the function and make the function send remote event for me ( line6 to line 8) and it worked!

  1. What do you want to achieve?
    I want to know what is the problem why sending directly doesn’t work?
    code:
local toClientCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinchangeToClient")
local toServerCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinChangetoServer")

local coinVal = 0

function toClientCoinUpdate(player, coinVal2)
	toClientCoinEvent:FireClient(player, coinVal2)
end

toServerCoinEvent.OnServerEvent:Connect(function(player, val)
	player.leaderstats.Coin.Value = val
	print("player = ", player)
	print("value = ", val)
	toClientCoinEvent(player, val)
end)

my message is so long I’m sorry ;-;
, thanks for your time

toClientCoinEvent is the event, I think you are trying to call the function toClientCoinUpdate.

when I used the toClientCoinEvent there’s an error:
attempt to call an Instance value
so I had to use remote event indirectly through a function

I wanna know what is causing da error to happen

you are calling the event, not the function.

This should work;

local toClientCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinchangeToClient")
local toServerCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinChangetoServer")

local coinVal = 0

function toClientCoinUpdate(player, coinVal2)
	toClientCoinEvent:FireClient(player, coinVal2)
end

toServerCoinEvent.OnServerEvent:Connect(function(player, val)
	player.leaderstats.Coin.Value = val
	print("player = ", player)
	print("value = ", val)
	toClientCoinUpdate(player, val)
end)

This can also work, without the extra function;

local toClientCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinchangeToClient")
local toServerCoinEvent = game:GetService("ReplicatedStorage"):WaitForChild("coinChangetoServer")

local coinVal = 0

toServerCoinEvent.OnServerEvent:Connect(function(player, val)
	player.leaderstats.Coin.Value = val
	print("player = ", player)
	print("value = ", val)
	toClientCoinEvent:FireClient(player, val)
end)
1 Like

you are trying to call the RemoteEvent instead of the function itself
replace toClientCoinEvent(player, val) to toClientCoinUpdate(player, val)

make sure you dont name your variables that may collide with other variables

1 Like

can you tell mee what’s causing the error? cuz incas
EDIT :oh wait okay I understand now

The RemoteEvent element is an instance, so when calling it like a function, it throws an error.

oh okayy I understand now thankss sorry I didn’t read the message above ;-;

Nah you’re all good, sometimes we just need another eye to look at our code.

1 Like

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