Hello there. I am working on a project right now, and part of it has to fire RemoteFunctions from Player > Server > Player2
It is not working apparently. On the server I made it print “sent” after it fires the event, and it does. On the client side of player2, I also made it print something when it receives the event, but it isn’t getting it!! I tried sending it to other players, and even to myself! There were no errors in the console. I have provided screenshots/code down below. Please help!!
Code:
Client:
local ids = {}
function create(text, typeOf, image, trading, player2)
local new = script.Parent.TemplateItem:Clone()
if not trading then
new:WaitForChild("Top"):WaitForChild("Notification").Visible = true
new.Top:WaitForChild("Trading").Visible = false
new.Top.Notification:WaitForChild("DescriptionVal").Value = text
if typeOf == "image" then
new.Top.Notification:WaitForChild("Object"):WaitForChild("Image").Image = image
elseif typeOf == "object" then
local object = image:Clone()
object.Parent = new.Top.Notification:WaitForChild("Object")
end
new.Name = text
else
new:WaitForChild("Top"):WaitForChild("Notification").Visible = false
new.Top:WaitForChild("Trading").Visible = true
new.Top.Trading:WaitForChild("TargetedPlayer").Value = player2
local image, isReady = game:GetService("Players"):GetUserThumbnailAsync(player2.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
new.Top.Trading:WaitForChild("Image").Image = image
new.Name = player2.UserId
end
new.Visible = true
new.Parent = script.Parent
new:TweenSize(UDim2.new(1, 0, 0.47, 0), "Out", "Sine", 0.2, true)
local id = #ids + 1
table.insert(ids, {Text = text, Object = new})
if not trading then
wait(7)
new:TweenSize(UDim2.new(0, 0, 0, 0), "In", "Sine", 0.2, true)
wait(0.2)
new:Destroy()
table.remove(ids, id)
end
end
game.ReplicatedStorage.Items.Events.RemoteEvents.Trade.OnClientInvoke = function(action, data)
print("got")
if action == "SendTrade" then
print("send trad")
local player2 = data.Player2
local player2Trading = player2:WaitForChild("Trading")
local player2TradesAllowed = player2Trading:WaitForChild("TradesAllowed")
local player2TradingWith = player2Trading:WaitForChild("TradingWith")
if player2TradesAllowed.Value and player2TradingWith.Value == "" then
print("can trade")
if not script.Parent:FindFirstChild(player2.UserId) then
print("doesnt exist")
if #ids >= 2 then
print("deleting old")
local toTween = ids[1].Object
toTween:TweenSize(UDim2.new(0, 0, 0, 0), "In", "Sine", 0.2, true)
wait(0.2)
toTween:Destroy()
create(player2.UserId, "", "", true, player2)
print("created")
else
create(player2.UserId, "", "", true, player2)
print("created")
end
end
end
end
end
game.ReplicatedStorage.Items.Events.RemoteEvents.Notification.OnClientEvent:Connect(function(text, typeOf, image)
if script.Parent:FindFirstChild(text) then
script.Parent[text].Notification.Top:WaitForChild("Count").Value += 1
else
if #ids >= 2 then
local toTween = ids[1].Object
toTween:TweenSize(UDim2.new(0, 0, 0, 0), "In", "Sine", 0.2, true)
wait(0.2)
toTween:Destroy()
create(text, typeOf, image)
else
create(text, typeOf, image)
end
end
end)
print("connected to all functions")
Server:
local replicatedStorage = game:GetService("ReplicatedStorage")
local items = replicatedStorage:WaitForChild("Items")
local remoteEvents = items:WaitForChild("Events"):WaitForChild("RemoteEvents")
local tradeEvent = remoteEvents:WaitForChild("Trade")
tradeEvent.OnServerInvoke = function(player, action, data)
local returning
if action == "SendTrade" then
local playerTrading = player:WaitForChild("Trading")
local playerTradesAllowed = playerTrading:WaitForChild("TradesAllowed")
local playerTradingWith = playerTrading:WaitForChild("TradingWith")
local player2 = data.Player2
local player2Trading = player2:WaitForChild("Trading")
local player2TradesAllowed = player2Trading:WaitForChild("TradesAllowed")
local player2TradingWith = player2Trading:WaitForChild("TradingWith")
if (player2TradesAllowed.Value and player2TradingWith.Value == "") and (playerTradesAllowed.Value and playerTradingWith.Value == "") then
returning = true
tradeEvent:InvokeClient(player2, "SendTrade", {Player2 = player})
print("successfully sent")
end
elseif action == "AcceptTrade" then
local playerTrading = player:WaitForChild("Trading")
local playerTradesAllowed = playerTrading:WaitForChild("TradesAllowed")
local playerTradingWith = playerTrading:WaitForChild("TradingWith")
local player2 = data.Player2
local player2Trading = player2:WaitForChild("Trading")
local player2TradesAllowed = player2Trading:WaitForChild("TradesAllowed")
local player2TradingWith = player2Trading:WaitForChild("TradingWith")
if (player2TradesAllowed.Value and player2TradingWith.Value == "") and (playerTradesAllowed.Value and playerTradingWith.Value == "") then
returning = true
playerTradingWith.Value = player2.UserId
player2TradingWith.Value = player.UserId
tradeEvent:InvokeClient(player, "StartTrade", {Player2 = player2})
tradeEvent:InvokeClient(player2, "StartTrade", {Player2 = player})
end
end
return returning
end