So I'm trying to make a LocalScript that connects to a ServerScript through a remote event which makes a Gui appear. The error is that every time I fire the remote event I need it to happen for one player only so I use :FireClient in the ServerScript but I get an error from the LocalScript saying "attempt to index boolean with 'waitforchild' and I don't know how to fix the error on my own
The error happens on Line 7
Here is my code
local player = game:GetService("Players").LocalPlayer
local ToggleTPMenuEvent = game.ReplicatedStorage.TeleportEvents.ToggleTPMenu
local TPMenu = player.PlayerGui.TeleportMenu.Frame
ToggleTPMenuEvent.OnClientEvent:Connect(function(Player:Player)
Player.PlayerGui:WaitForChild("TeleportMenu"):WaitForChild("Frame").Visible = true
Player.PlayerGui:WaitForChild("TeleportMenu"):WaitForChild("Frame"):WaitForChild("TextLabel").Visible = true
Player.PlayerGui:WaitForChild("TeleportMenu"):WaitForChild("Frame"):WaitForChild("PlayButton").Visible = true
Player.PlayerGui:WaitForChild("TeleportMenu"):WaitForChild("Frame"):WaitForChild("ChaptersFrame").Visible = true
end)
When you fire a RemoteEvent from the server, the Player argument does not get passed to the client.
If the server calls...
remoteEvent:FireClient(player1, a, b, c)
The client will receive...
remoteEvent.OnClientEvent:Connect(function(a, b, c)
In your code, your client event handler is trying to handle the Player argument, but actually the value being assigned to the Player
argument is a Boolean.
Since this is a LocalScript, use the Players.LocalPlayer
to get the gui. You're already doing this, so just use the TPMenu
variable. Then, use the boolean from the server script to toggle the visibility :
local player = game:GetService("Players").LocalPlayer
local ToggleTPMenuEvent = game.ReplicatedStorage.TeleportEvents.ToggleTPMenu
ToggleTPMenuEvent.OnClientEvent:Connect(function(isVisible)
local TPMenu = player.PlayerGui.TeleportMenu.Frame
TPMenu.Visible = isVisible
TPMenu.TextLabel.Visible = isVisible
TPMenu.PlayButton.Visible = isVisible
TPMenu.ChaptersFrame.Visible = isVisible
end)