Why is my FireClient not working?

Here’s my code.

Server:
if tplrs > 0 then
local plrs = game.Teams.T:GetPlayers()
local random = plrs[math.random(1, #plrs)]
game.ReplicatedStorage.Events.EquipGun:FireClient(random.Name) --oops
end
Client:
game.ReplicatedStorage.Events.RequestGun.OnClientEvent:Connect(function(name)
if name == game.Players.LocalPlayer.Name then
print(“test”)
end
end)

Does it have something to do with my character respawning?

Only seeing half of the code here - can please you show the code that receives the FireClient call? Additionally, please clarify the type of script your code is in.

Okay. I will do that right now.

game.ReplicatedStorage.Events.RequestGun.OnClientEvent:Connect(function(name)
if name == game.Players.LocalPlayer.Name then
print(“test”)
end
end)

The issue is that name is nil.

When using FireClient and passing a player, you are sending a request from the server to one client, telling that one client to do something. That player is accessed via game.Players.LocalPlayer on the client. FireClient and FireAllClients does not pass a player, or their name or anything. Nor do you need one, because you have game.Players.LocalPlayer (which will always be the player that you used in FireClient)

Okay. I will try this and see if it works

You just modified your code to show that you’re passing the name of the player. This won’t work. You need to pass the actual player instead, and the OnClientEvent doesn’t receive that player (because you have LocalPlayer)

Yeah I thought it would work just with that but I was wrong.

It won’t. From the Roblox docs:

I am new to coding on roblox and it’s pretty hard