hello devs
im currently making a script that get player friend’s id and send it to server, then make it as npc
but while sending id in client to server, error happens
heres my script
client
local Players = game:GetService("Players")
local PLR = Players.LocalPlayer
local CHAR = PLR.Character or PLR.CharacterAdded:Wait()
while true do
wait(1)
warn("repeat")
local loc = script.Parent["Start Door"]
warn("checking if Spawn1 is true")
if loc.Spawn1.Value == true then
local success, friendPages = pcall(function()
return Players:GetFriendsAsync(PLR.UserId)
end)
if not success then
warn("There was a error while getting player's friend id!")-- remember to handle pcall errors
return
end
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum += 1
end
end)
end
local userIds = {}
for item, _pageNo in iterPageItems(friendPages) do
table.insert(userIds, item.Id)
end
local randomFriend = userIds[math.random(1, #userIds)]
game.ReplicatedStorage.char:FireServer(Players ,CHAR, randomFriend)
wait(20)
end
end
server
warn("is this even started")
game.ReplicatedStorage.char.OnServerEvent:Connect(function(Players, CHAR, randomFriend)
print(randomFriend) -- in there, it prints my name not id
warn("here?")
local newFriend = Players:CreateHumanoidModelFromUserId(randomFriend)
newFriend.Parent = CHAR
newFriend:FindFirstChild("HumanoidRootPart").Anchored = false
newFriend.Name = "Customer"
warn("spawned")
local NPClogic = script:WaitForChild("Move Script"):Clone()
NPClogic.Parent = newFriend
NPClogic.Enabled = true
end)