How to make a Script that NPC will spawn if Player Joined the game

help please im noob at scripting :frowning_face:

i just need a script that spawn NPC i just know like this

game.Players:WaitForChild("Players")
(NPC spawn Code)

i dont know if that script works

1 Like

There’s a event that fires whenever a player joined

game.Players.PlayerAdded:Connect(function()
  -- npc spawn code
end)

This must be done in a server script btw for the best result because you want to spawn a npc

1 Like

yo bro Thank you for the script so this is my script

game.Players.PlayerAdded:Connect(function()
	local ServerStorage = game:GetService('ServerStorage')
	local NPC = ServerStorage.Enemies.Musuh:Clone()
	NPC.Parent = game.Workspace.Enemies
	NPC.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Spawn.Position + Vector3.new(0,5,0))
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.