I have a script that is meant to make a GUI visible to a player when an OnClientEvent occurs. However, the script keeps erooring stating that "ScreenGui is not a valid member of (playername).PlayerGui, despite the fact that it clearly is. I’m at a loss here so any help would be greatly appreciated!
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local challengeRecieved = game.ReplicatedStorage.PlayerChallengedClientRecieve
local challengeAnnounce = LocalPlayer.PlayerGui.ScreenGui.ChallengeAnnouncePlayer
challengeRecieved.OnClientEvent:Connect(function(Player, name)
local challengeUI = LocalPlayer.PlayerGui.ScreenGui.ChallengeAnnouncePlayer
challengeUI.Visible = true
challengeUI.YouveBeenChallenged.Text = ("You have been challenged by" ..Player)
end)
challengeAnnounce.ChallengeAccept.MouseButton1Down:Connect(function()
print("Player has accepted the challenge!")
local battleQueue = game.ReplicatedStorage.BattleQueue
battleQueue:FireServer()
end)
challengeAnnounce.ChallengeDeny.MouseButton1Down:Connect(function()
print("Player has denied the challenge!")
challengeAnnounce.Visible = false
end)
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local challengeRecieved = game.ReplicatedStorage:WaitForChild(“PlayerChallengedClientRecieve”)
local challengeAnnounce = LocalPlayer:WaitForChild(“PlayerGui”):WaitForChild(“ScreenGui”):WaitForChild(“ChallengeAnnouncePlayer”)
challengeRecieved.OnClientEvent:Connect(function(Player, name)
challengeAnnounce.Visible = true
challengeAnnounce.YouveBeenChallenged.Text = "You have been challenged by " … Player.Name
end)
challengeAnnounce.ChallengeAccept.MouseButton1Down:Connect(function()
print(“Player has accepted the challenge!”)
local battleQueue = game.ReplicatedStorage:WaitForChild(“BattleQueue”)
battleQueue:FireServer()
end)
challengeAnnounce.ChallengeDeny.MouseButton1Down:Connect(function()
print(“Player has denied the challenge!”)
challengeAnnounce.Visible = false
end)
‘’’
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local challengeRecieved = game.ReplicatedStorage:WaitForChild(“PlayerChallengedClientRecieve”)
local challengeAnnounce = LocalPlayer:WaitForChild(“PlayerGui”):WaitForChild(“ScreenGui”):WaitForChild(“ChallengeAnnouncePlayer”)
challengeRecieved.OnClientEvent:Connect(function(Player, name)
challengeAnnounce.Visible = true
challengeAnnounce.YouveBeenChallenged.Text = "You have been challenged by " … Player.Name
end)
challengeAnnounce.ChallengeAccept.MouseButton1Down:Connect(function()
print(“Player has accepted the challenge!”)
local battleQueue = game.ReplicatedStorage:WaitForChild(“BattleQueue”)
battleQueue:FireServer()
end)
challengeAnnounce.ChallengeDeny.MouseButton1Down:Connect(function()
print(“Player has denied the challenge!”)
challengeAnnounce.Visible = false
end
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rep=game:GetService("ReplicatedStorage")
local challengeRecieved = rep:WaitForChild("PlayerChallengedClientRecieve")
local challengeAnnounce = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
:WaitForChild("ChallengeAnnouncePlayer")
..
..
Now we know everything is set up and can move on …
Also this: local challengeUI = LocalPlayer.PlayerGui.ScreenGui.ChallengeAnnouncePlayer
has already been defined as challengeAnnounce
You did this so fast it didn’t get the gui location, so when you referenced it later, it had no clue.
Also I’m stalling with humanoid because it’s a great stall.
The reason this stuff is needed is it takes a little bit for the player to completely load into the game. Your error is a dead giveaway you did not give that the time it needed.
Sorry, stuff happened last night. Didn’t get time. However, the WaitForChild() statement worked, it seems that the script was being executed faster than it could all be loaded in. Not sure why I didn’t think of this as it has happened to me before, but I am grateful for the help you guys gave me here. The code is working again and all is good. Apologies for not responding last night, as I said stuff was going on for me all of a sudden and I just couldn’t find the time. Thank you all.