So, I'm trying to do a Gui that shows up to all the players when someone (an HR from my group) clicks another button. I get an error from the Script that is inside of the Gui, that says "Unable to cast value to Object" https://gyazo.com/8d6591d0cd133a22e61f5f0711b0e298
local RemoteEvent = game.ReplicatedStorage.AdvertEvent
function Click()
local Player = script.Parent.Parent.Parent.Parent.Parent.Name
RemoteEvent:FireClient(Player)
end
script.Parent.MouseButton1Click:Connect(Click)
I have a LocalScript inside StarterPlayer > StarterPlayerScripts > Events > LocalScript that puts:
local AdvertEvent = game.ReplicatedStorage.AdvertEvent
local Player = game.Players.LocalPlayer
function ShowAdvert()
local Gui = game.StarterGui.AdvertGui
if (not Player.PlayerGui:FindFirstChild(Gui.Name)) then
Gui.Parent = Player.PlayerGui
end
end
AdvertEvent.OnClientEvent:Connect(ShowAdvert)

4 comments
Casting means converting something of one datatype into another datatype. In your first script at line 4 I'm assuming you're getting the name of the Player.. FireClient takes a Player object for its argument. The Name property gets a string, not a Player, therefor an invalid cast. Use FireClient and pass an actual Player, not a string.
Now I get the error "Argument 1 missing or nil" in line 5. Maybe because it should be a LocalScript (becuase it's inside a Gui)
FireClient can only be used in server-scripts. That's what server-client communication is. Argument 1 is nil because script.Parent.Parent.Parent.Parent.Parent is nil.
Now it says "FireClient: player argument must be a Player object" (I removed one ".Parent")