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.
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.
--// 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 \\--
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
--// 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