Hello! i had someone help me make a script about spawning a friends character, however i only want it to spawn however many parts are in a folder. For example: 5 parts in a folder, 5 characters to spawn.
Also, i want it to only spawn them if the part is empty and not spawn them at a part where another character is.
Can anyone help me do this?
Code:
task.wait()
function SpawnFriend()
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(0.1)
local Parts = workspace:WaitForChild("A"):GetChildren()
local function GetRandomFriend()
return FriendIDs[math.random(1, #FriendIDs)]
end
for i,v in pairs(Parts) do
v.CanCollide = false
end
local SelectedFriend = GetRandomFriend()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(SelectedFriend)
FriendCharacter:PivotTo(Parts[math.random(1, #Parts)].CFrame)
FriendCharacter.Parent = workspace
end
while true do
local success, err = pcall(SpawnFriend)
task.wait(0.1)
end
– ScxiptedShark