I am making a game where you can select a person based on a GUI to battle. When you click on the battle button, it should retrieve the default request GUI from the storage and send it to the player you want to battle.
The problem is that the GUI does not actually get sent to the player's GUI. The error I am getting is: "Infinite yield possible on 'Players.Player2:WaitForChild("PlayerGui")'" when testing with two people.
Is there anyway to fix this so that the Request GUI is properly sent to the desired player's GUI?
The Script is a LocalScript inside a button.
local id = script.Parent.Parent:WaitForChild("PlayerID") -- Player's ID
local text = script.Parent:WaitForChild("Battletext")
local searching = game:GetService('Players').LocalPlayer:WaitForChild("WaitingForPlayer") -- bool value that identifies if you are waiting for the player to accept or decline the request.
local Request = game.ReplicatedStorage.DefaultRequest
local localgui = game:GetService('Players').LocalPlayer:WaitForChild("PlayerGui")
local localplayerid = game.Players.LocalPlayer.UserId
local lookfor = game.ReplicatedStorage.RemoteEvent
local lookForGameNextClick = true
local player = game:GetService("Players"):GetPlayerByUserId(id.Value)
script.Parent.MouseButton1Click:connect(function()
print(id.Value)
print(localplayerid)
if id.Value == localplayerid then
script.Disabled = true
text.Text = "Can't Do That"
wait(2)
script.Disabled = false
text.Text = "BATTLE"
else
if searching.Value == false then
text.Text = "Cancel"
searching.Value = true
print("searching")
sendmessage() ----------------------------------------
return
end
if searching.Value == true and text.Text == "Cancel" then
text.Text = "BATTLE"
searching.Value = false
print("canceled")
return
else
text.Text = "Waiting!" -- waiting for player to accept or decline
script.Disabled = true
wait(2)
text.Text = "BATTLE"
script.Disabled = false
end
end
end)
function sendmessage()
local message = Request:Clone()
if player then
print("Worked")
local guie = player:WaitForChild("PlayerGui")
message.Parent = guie
else
print("Player with userId 1 is not in this server!")
end
end

1 comment
Omg, Thank you so much!