✓ Accepted answer
Roblox does not support direct client to client communication. All events have to go through the server. Therefore you will need two separate RemoteEvents. First one will fire server with the challenge, and the other will fire respective client.
Lets start with the server script. Put this one in ServerScriptSercvice:
ReplicatedStorage = game:GetService("ReplicatedStorage")
ReceiveChallenge = Instance.new("RemoteEvent")
ReceiveChallenge.Name = "ReceiveChallenge"
ReceiveChallenge.Parent = ReplicatedStorage
ForwardChallenge = Instance.new("RemoteEvent")
ForwardChallenge.Name = "ForwardChallenge"
ForwardChallenge.Parent = ReplicatedStorage
function OnReceiveChallenge(player,challengedPlayer)
print(player.Name .. " challenged " .. challengedPlayer.Name)
ForwardChallenge:FireClient(challengedPlayer,player)
end
ReceiveChallenge.OnServerEvent:Connect(OnReceiveChallenge)
Now for Your LocalScript. You have not provided the script section, where You are handling incoming event, so I took some liberty in providing an example:
Players = game:GetService("Players")
ReplicatedStorage = game:GetService("ReplicatedStorage")
ReceiveChallenge = ReplicatedStorage:WaitForChild("ReceiveChallenge")
ForwardChallenge = ReplicatedStorage:WaitForChild("ForwardChallenge")
script.Parent.MouseButton1Click:Connect(function()
playerName = script.Parent.Parent.TextLabel.Text
challengedPlayer = Players:FindFirstChild(playername)
print(challengedPlayer.Name.." Found")
ReceiveChallenge:Fire(challengedPlayer)
end)
function OnReceiveChallenge(playerWhoChallengedMe)
print(playerWhoChallengedMe.Name .. " challenged me!")
end
FrowardChallenge.OnClientEvent:Connect(OnReceiveChallenge)
2 comments
To communicate between players, You need to use RemoteEvent located in ReplicatedStorage. Bindable Event can only work locally on one client (or internally on server).
I prefer RemoteEvent because RemoteEvent already have the thing "player" once you put it inside the function() thing