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)
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
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.
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.
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