(Help) With a friend's ID script

Hello community, I need help how to identify if a friend is playing and if he does then put his reward as in the next Local Script, the problem is that it does not work, who can help me, please?

   game.Players.PlayerAdded:Connect(function(player)
    	if player:IsFriendsWith() then
    		script.Parent.Visible = true
    		wait(0.1)
    		game.Players.LocalPlayer.WalkSpeed = 32
    		game.Players.LocalPlayer.JumpPower = 100
    	end
    end)

You need to put your UserId in the parenthesis in the IsFriendsWith function so the script knows which to players’ friendship to check

if player:IsFriendsWith(123456789) then -- your UserId

Apparently I was wrong, I mean how do I get friends who are playing online?

1 Like
game.Players.PlayerAdded:Connect(function()
	
	local Players = game:GetService("Players")
	local player = Players.LocalPlayer
	local onlineFriends = player:GetFriendsOnline(10)
	
	if onlineFriends == true then
	
		script.Parent.Visible = true
		wait(0.1)
		game.Players.LocalPlayer.WalkSpeed = 32
	    game.Players.LocalPlayer.JumpPower = 100
	end	
end)

??

It needs to be in a localscript so first create a remote event to send a request to the server. PlayerAdded will not work on the client because the localscript runs by the time the player exists.

local players = game:GetService('Players')

local friendsOnline = players.LocalPlayer:GetFriendsOnline(200)

game:GetService('ReplicatedStorage').RemoteEventName:FireServer(friendsOnline) -- sends a request to the server

Now look at how to use the request on the server by looking at the OnServerEvent function: Custom Events and Callbacks | Documentation - Roblox Creator Hub

Edit: Just tested it so yes, it should work.

Local Script:

local players = game:GetService('Players')
local friendsOnline = players.LocalPlayer:GetFriendsOnline(200)

game:GetService('ReplicatedStorage').Friends:FireServer(friendsOnline)

Script:

    game.Players.PlayerAdded:Connect(function()

    	local Players = game:GetService("Players")
    	local player = Players.LocalPlayer
    	local onlineFriends = player:GetFriendsOnline(10)

    	if onlineFriends == true then
    		script.Parent.Visible = true
    		wait(0.1)
    		game.Players.LocalPlayer.WalkSpeed = 32
    		game.Players.LocalPlayer.JumpPower = 100
    	end	
    end)

You need to use the OnServerEvent feature (from the developer hub link I just sent you)

game:GetService('ReplicatedStorage').RemoteEventName.OnServerEvent:Connect(function(player,friendsonline)
 --use the same code from the friends online script but replace the variable
end)

Make sure you inserted a remote event in replicated storage. This one should be the server script. LocalPlayer can’t be called from the server btw.

oh sure,

game:GetService('ReplicatedStorage').Friends.OnServerEvent:Connect(function(player,friendsonline)
script.Parent.Visible = true
wait(0.1)
game.Players.LocalPlayer.WalkSpeed = 3
game.Players.LocalPlayer.JumpPower = 100
end)

I thought you were gonna use the online friends script? Anyway localPlayer can’t be called from a server script. Use the “player” argument.

game:GetService('ReplicatedStorage').Friends.OnServerEvent:Connect(function(player,friendsonline)
script.Parent.Visible = true
wait(0.1)
player.Character.Humanoid.WalkSpeed = 3
player.Character.Humanoid.JumpPower = 100
end)

Edit: Use my edit sorry

Oh, nothing happens

game:GetService('ReplicatedStorage').Friends.OnServerEvent:Connect(function(player,friendsonline)

game.StarterGui.FriendLy.Amigo.Visible = true

wait(0.1)

player.Character.Humanoid.WalkSpeed = 3

player.Character.Humanoid.JumpPower = 100

end)

The StarterGui is a place where you want guis to automatically be cloned to the playergui. You need to disable the visible property in the player’s playergui not in startergui.

player.PlayerGui.Friendly.Amigo.Visible = true

Edit: I made a mistake, I didn’t do player.PlayerGui. Use this code instead.

It still doesn’t work for me, so strange, a Gui should appear in the red box

Say “/console” and if there’s any errors show me.

I gave the GUI - Amigo.Visible = true and if I get it but the code doesn’t work

Screenshot_48

add the script to serverscriptsservice not serverstorage

Look I’ll tell you something, what is supposed to be is that when the friend enters. The GUI then appears, and what happens is that if I put it Visible = true all people will see it

Edited: There I have it Visible = true

1 Like

what do i do?, so that when the friend enters then this GUI :frowning: