So, I made a script wich fires a bindable event whenever one player decides to challenge the other one to a game. The other one should recieve an invite, but i see this:
Infinite yield possible on 'Players.Player1:WaitForChild("PlayerGui")'
I know what it means, etc. But why does it show up when it actually exists? Bindable event is located inside the gui responsible for the invite. I did the code etc but what is wrong with this one?
local playername = nil local player = nil local Event = nil script.Parent.MouseButton1Click:Connect(function() playername = script.Parent.Parent.TextLabel.Text player = game.Players:FindFirstChild(playername) print(player.Name.." Found") Event = player:WaitForChild("PlayerGui").ChallengeGUI.Challenge --This causes the error print("Challenged ".. playername) Event:Fire() end)
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") --Create events here. You can also create them manually, by right-clicking on replicated storage. 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) --opposite order 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) --next function handles incoming challenges function OnReceiveChallenge(playerWhoChallengedMe) print(playerWhoChallengedMe.Name .. " challenged me!") --update some GUI element with that message end FrowardChallenge.OnClientEvent:Connect(OnReceiveChallenge)