lolformon
(Monsparkles19)
December 31, 2022, 6:33am
#1
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!
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
GuySalami
(GuySalami)
December 31, 2022, 6:34am
#2
toClientCoinEvent
is the event, I think you are trying to call the function toClientCoinUpdate
.
lolformon
(Monsparkles19)
December 31, 2022, 6:37am
#3
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
lolformon
(Monsparkles19)
December 31, 2022, 6:37am
#4
I wanna know what is causing da error to happen
GuySalami
(GuySalami)
December 31, 2022, 6:38am
#5
you are calling the event, not the function.
GuySalami
(GuySalami)
December 31, 2022, 6:38am
#6
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
Artzified
(Artzified)
December 31, 2022, 6:39am
#7
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
lolformon
(Monsparkles19)
December 31, 2022, 6:40am
#8
can you tell mee what’s causing the error? cuz incas
EDIT :oh wait okay I understand now
GuySalami
(GuySalami)
December 31, 2022, 6:41am
#9
The RemoteEvent element is an instance, so when calling it like a function, it throws an error.
lolformon
(Monsparkles19)
December 31, 2022, 6:42am
#10
oh okayy I understand now thankss sorry I didn’t read the message above ;-;
GuySalami
(GuySalami)
December 31, 2022, 6:43am
#11
Nah you’re all good, sometimes we just need another eye to look at our code.
1 Like
system
(system)
Closed
January 14, 2023, 6:43am
#12
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.