Script prints nil instead of the players' name

Hello! I tried to make a player info GUI. I want it so that when you click a player, a GUI appears and shows information about him. (For now it’s just the username)

local Events = game.ReplicatedStorage:WaitForChild("Events")

local ClickedPlayerInfo = Events.ClickedPlayerInfoEvent

script.Parent.MouseClick:Connect(function(playerwhoclicked,viewplayerinfo)

ClickedPlayerInfo:FireClient(playerwhoclicked, game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent))

end)

This script is inside a ClickDetector which is inside a part that’s supposed to be the hitbox. This hitbox is inside every players character.

local Events = game.ReplicatedStorage:WaitForChild("Events")
local PlayerInfoEvent = Events.ClickedPlayerInfoEvent

PlayerInfoEvent.OnClientEvent:Connect(function(playerthatclicked,viewplayerinfo)
	local frame = game.Players.LocalPlayer.PlayerGui.PlayerInfoGui.PlayerInfoFrame
	frame.Visible = true
	print(viewplayerinfo)
end)

This script is inside the StarterPlayerScripts. It’s supposed to print the name of the player whose hitbox has been clicked. But instead it just prints “nil”
Thanks for reading!

1 Like

Remove the first parameter, you only have to put the player who fired the event as the first parameter in OnServerEvent, raeson is simply because you can just get the LocalPlayer for OnClientEvent

PlayerInfoEvent.OnClientEvent:Connect(function(viewplayerinfo)
3 Likes