In this tutorial, I will teach you how to make a spawner that spawns Dummies as a User/Player’s FRIEND!
First to start off, make a script in ServerScriptService. (Name it whatever you’d like.)
Second, in workspace, make a part (any size, shape, position) and name it “Spawner”.
Inside the Server Script, we will find the Spawner instance inside the workspace.
local spawner = workspace:WaitForChild("Spawner") --Find the Spawner inside the Workspace!
Third, you will want ANY dummy/character model.
We will find the model inside the Script.
local spawnDummy = workspace:WaitForChild("Dummy") --Find the Model inside the Workspace!
Next, we will pick a random player inside the game, and pick a random friend.
We’ll loop it in a ‘while’ loop so it continuously runs!
while task.wait(5) do --Change the time to how long you want it to Spawn
local existingPlayers = game:GetService("Players"):GetChildren() --Get all the existing Players through the :GetPlayers() Function.
if #existingPlayers > 0 then --Checks if there are any players.
local selectedPlayer = existingPlayers[math.random(1, #existingPlayers)] --Pick a random player
local friendsTable = {} --A Table that stores friend's IDs.
local friendList = game:GetService("Players"):GetFriendsAsync(selectedPlayer.UserId) --Get the player's Friends
local count = 0
while wait() do --Loops through all the friends.
for _, item in ipairs(friendList:GetCurrentPage()) do
count += 1
friendsTable[count] = item.Id
end
if friendList.IsFinished then --Checks if there are anymore friends left.
break
end
friendList:AdvanceToNextPageAsync()
end
if #friendsTable > 0 then --Checks if the player has any friends.
local selectedFriend = friendsTable[math.random(1, #friendsTable)] --Get a friend!
local friendAppearance = game:GetService("Players"):GetHumanoidDescriptionFromUserId(selectedFriend) --Get the Friend's Appearance
local dummyClone = spawnDummy:Clone() --Creates a clone of the Specified 'spawnDummy'
dummyClone:SetPrimaryPartCFrame(CFrame.new(spawner.Position + Vector3.new(0, 3, 0))) --Sets the dummy's CFrame to the spawner's Position + 3 Studs Y (Up)
dummyClone.Parent = workspace --Sets the parent of the clone to the workspace.
dummyClone.Humanoid:ApplyDescriptionReset(friendAppearance) --Applies the Friend's appearance to the Dummy
else
warn("The specified player has NO FRIENDS!")
end
else
warn("There are no players in the game!")
end
end
That should be the end of the tutorial! Hope that helped!
If you have any questions, reply please!