The issue
Calling StarterGui:GetCore("PlayerFriendedEvent")
and StarterGui:GetCore("PlayerUnfriendedEvent")
return BindableEvent objects which should be called whenever the local player becomes friends with someone or unfriends someone as per the documentation:
And although this does indeed happen, these BindableEvent objects are in fact fired much more often, at inappropriate times.
Current behavior
The PlayerFriendedEvent BindableEvent is called whenever:
- You become friends with someone during gameplay.
- A friend of yours joins the game, but only the first time they join the game during your gameplay session.
- You join a server your friends are in. The BindableEvent is called for every friend in the server.
The PlayerUnfriendedEvent BindableEvent is called whenever:
- You unfriend someone during gameplay.
- A player you are no friends with joins the game, but only the first time they join the server during your gameplay session.
- You join a server where some players are no friends of yours. The BindableEvent is called for non-friend in the server.
Expected behavior
The PlayerFriendedEvent should only be called whenever:
- You become friends with someone during gameplay.
The PlayerUnfriendedEvent should only be called whenever:
- You unfriend someone during gameplay.
Reproducing the bug
I used this LocalScript to verify the unexpected behavior.
------------------------[[ = VARIABLES = ]]------------------------
--local Plr = game.Players.LocalPlayer
local StarterGui = game:GetService("StarterGui")
------------------------[[ = COREGUI LOGIC = ]]------------------------
local FriendedRemote = StarterGui:GetCore("PlayerFriendedEvent")
local UnfriendedRemote = StarterGui:GetCore("PlayerUnfriendedEvent")
FriendedRemote.Event:Connect(
function(Plr, ...)
print("Friended", Plr, ...)
--game.ReplicatedStorage.ChangeFriendship:FireServer(Plr, "Friended")
end
)
UnfriendedRemote.Event:Connect(
function(Plr, ...)
print("Unfriended", Plr, ...)
--game.ReplicatedStorage.ChangeFriendship:FireServer(Plr, "Unfriended")
end
)
I had a couple friends join me in a mostly empty game with that LocalScript. This is what my output looked like after these friends joined:
This is what the output looked like from XAXA’s perspective upon joining the game:
Notice how for both me and XAXA the output prints two names when in reality it should not print any names at all! We did not send friend requests nor unfriend each other during this time, so none of these prints should have been called.
Thank you @xaxa and @peteyk473 for helping me test this.
Why this should be fixed
Aside from obviously being unintended behavior which should always be fixed, this makes the logic for a piece of code I am working on significantly more complex. I am working on a Script which tracks for each player in the server with whom they are friends. The server has no way of knowing when friendship statuses between two players change except for constantly polling game.Players:GetFriendsAsync(Player.UserId)
, which of course takes up significantly more computing and networking resources than necessary. This is why I am using the PlayerFriendedEvent and PlayerUnfriendedEvent BindableEvents, but these signals are not reliable at all in their current state.