Help with :SetCore SendNotification

I need help with callbacks for SetCore SendNotification, however I am facing issues.

I am getting an error whenever I try using Callbacks for SendNotification due to me still being new to RemoteFunctions, however I am very confident with RemoteEvents. The issue is I’m unable make a function whenever the remotefunction is invoked, I’ve checked other devforum posts and they use the following line:

function RemoteFunction.OnInvoke(response)
end

And whenever I use this line of code, I encounter this error:

OnInvoke is not a valid member of RemoteFunction "ReplicatedStorage.RemoteFunctions.TradeClientResponse"

If you’d you like to see all my code, simply respond in this post’s comments and I’ll reply as soon as I can.

Please show us the entire code, that’d help.

Plus, please avoid naming functions and remotes/variables/events in the same name.
With RemoteFunctions, unlike RemoteEvents, you’ll have to call it on the server in this way:

game.ReplicatedStorage["YourRemote"].OnServerInvoke = function(Player)
--player will always be the first parameter
end

Also, OnInvoke isn’t an event of remotes, but only of Blindable functions.

I am pretty sure you would have to use:

game.ReplicatedStorage.RandomRemoteFunction.OnServerInvoke = function() --// or OnClientInvoke

end

OnInvoke is used for BindableFunctions. As seen here.

1 Like

Should be like this:

RemoteFunction.OnServerInvoke = function()

end

or

RemoteFunction.OnClientInvoke = function()

end

Hello,

Here is the entire code:

--// SERVICES \\--

local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


--// VARIABLES \\--

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local RemoteFunctions = ReplicatedStorage:WaitForChild("RemoteFunctions")

local SendTradeNotification = RemoteEvents:WaitForChild("SendTradeNotification")
local TradeClientResponse = RemoteFunctions:WaitForChild("TradeClientResponse")


--// FUNCTIONS \\--

function TradeClientResponse.OnInvoke(response)
	print(response .. " chosen")
	New_Notification("⚠ Trade Error!", "An error has occurred when sending trade response.", nil, 5, nil, nil, nil)
end

function New_Notification(title, text, icon, duration, callback, button1, button2)
	local NotifTable = {
		Title = title,
		Text = text,
		Icon = icon,
		Duration = duration,
		Callback = callback,
		Button1 = button1,
		Button2 = button2
	}
	
	for i=1, #NotifTable do
		print(NotifTable[i])
	end
	
	StarterGui:SetCore("SendNotification", NotifTable)
end


--// REMOTES \\--

--TradeClientResponse.OnServerInvoke = TradeClientResponse

SendTradeNotification.OnClientEvent:Connect(function(sender)
	local PlayerShotType = Enum.ThumbnailType.HeadShot
	local PlayerShotSize = Enum.ThumbnailSize.Size60x60
	local PlayerShot = game.Players:GetUserThumbnailAsync(sender.UserId, PlayerShotType, PlayerShotSize)

	local notif_text = sender.Name.. " would like to trade with you!"

	New_Notification("⇄ Trade Request!", notif_text, PlayerShot, 5, TradeClientResponse, "Accept", "Decline")
end)

--// MAIN \\--
--// SERVICES \\--

local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


--// VARIABLES \\--

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local RemoteFunctions = ReplicatedStorage:WaitForChild("RemoteFunctions")

local SendTradeNotification = RemoteEvents:WaitForChild("SendTradeNotification")
local TradeClientResponse = RemoteFunctions:WaitForChild("TradeClientResponse")


--// FUNCTIONS \\--

function New_Notification(title, text, icon, duration, callback, button1, button2)
	local NotifTable = {
		Title = title,
		Text = text,
		Icon = icon,
		Duration = duration,
		Callback = callback,
		Button1 = button1,
		Button2 = button2
	}
	
	for i=1, #NotifTable do
		print(NotifTable[i])
	end
	
	StarterGui:SetCore("SendNotification", NotifTable)
end


--// REMOTES \\--

TradeClientResponse.OnServerInvoke = function()
	print(response .. " chosen")
	New_Notification("⚠ Trade Error!", "An error has occurred when sending trade response.", nil, 5, nil, nil, nil)
end

SendTradeNotification.OnClientEvent:Connect(function(sender)
	local PlayerShotType = Enum.ThumbnailType.HeadShot
	local PlayerShotSize = Enum.ThumbnailSize.Size60x60
	local PlayerShot = game.Players:GetUserThumbnailAsync(sender.UserId, PlayerShotType, PlayerShotSize)

	local notif_text = sender.Name.. " would like to trade with you!"

	New_Notification("⇄ Trade Request!", notif_text, PlayerShot, 5, TradeClientResponse, "Accept", "Decline")
end)

--// MAIN \\--

Hello,

I have tried using OnClientInvoke however I receive no call for the function whatsoever.

Also I am unable to use OnClientInvoke due to the fact this is happening in a client script.

This is being used in a client script, so I am unable to use ‘OnServerInvoke’

I am pretty sure you can just change it to OnClientInvoke, since it can be used in LocalScripts.

I have tried that, however (as shown in the full code) nothing prints when a response is sent.

Edit: Is this causing due to the RemoteFunction being invoked and called in the same script?

RemoteFunctions are used for returning stuff. Try returning something with the remotefunction and print what it returned.

game.ReplicatedStorage.RemoteFunction.OnClientInvoke = function()
      return "Hi!"
end
print(remotefunc)

Yes. You would have to use remotefunctions with a local script and a server script.

The server script wants to get something from the RemoteFunction. So we use :InvokeClient
Then when the remotefunction returns something, you can get it from the variable you made.

--// SERVER
local mything = game.ReplicatedStorage.Remote:InvokeClient(plr)
print(mything)

--// CLIENT
game.ReplicatedStorage.Remote.OnClientInvoke = function()
    return "hi!"
end

--// If you actually want to make sure, use this:
game.ReplicatedStorage.Remote.OnClientInvoke = function()
    return math.random(1,255)
end

Thanks for your response,

I will try now.
I will edit this post when I have attempted.

Hello,

How would I invoke the server when a response is made by the client when accept or decline is pressed?

Thanks,

--// SERVER
local mything = game.ReplicatedStorage.Remote:InvokeClient(plr)
print(mything)

--// CLIENT

--// PlayerHasAccepted should be if the player has declined, or not.
game.ReplicatedStorage.Remote.OnClientInvoke = function()
    return PlayerHasAccepted
end

Hello,

PlayerHasAccepted wasn’t defined.

You would have to make it so that PlayerHasAccepted changes when the player has declined or not.

local PlayerHasAccepted = false -// Make it true if the player accepts

I think you misread the documentation…


Look a bit closer.

Even closer…
image

What you need is a BinadbleFunction not a RemoteFunction they are two different things.

The code is perfectly find but sometimes it can be quite hard to mistake this:
image
They do have very similar icons.

Hope this helps!

1 Like

Oh my god, I didn’t realize this, Thank you!