Script to Create and Control Noob Character
This script will create a new character (noob) in ServerStorage, make it walk on a part in Workspace, and control its movement between two parts.
ServerScriptService Script
-- Services
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
-- Configuration
local noobCharacterName = "Noob"
local noobFolderName = "Noobs Folder"
local npcWalkFolderName = "NPCWalk Folder"
local walkPartName = "walk"
local startPartName = "Start"
local endPartName = "End"
-- Create noob character
local noobCharacter = ServerStorage:FindFirstChild(noobCharacterName)
if not noobCharacter then
noobCharacter = Instance.new("Model")
noobCharacter.Name = noobCharacterName
local humanoid = Instance.new("Humanoid")
humanoid.Name = "Humanoid"
noobCharacter:AddChild(humanoid)
local head = Instance.new("Part")
head.Name = "Head"
head.Size = Vector3.new(1, 1, 1)
noobCharacter:AddChild(head)
local torso = Instance.new("Part")
torso.Name = "Torso"
torso.Size = Vector3.new(1, 2, 1)
noobCharacter:AddChild(torso)
local leftArm = Instance.new("Part")
leftArm.Name = "Left Arm"
leftArm.Size = Vector3.new(1, 2, 1)
noobCharacter:AddChild(leftArm)
local rightArm = Instance.new("Part")
rightArm.Name = "Right Arm"
rightArm.Size = Vector3.new(1, 2, 1)
noobCharacter:AddChild(rightArm)
local leftLeg = Instance.new("Part")
leftLeg.Name = "Left Leg"
leftLeg.Size = Vector3.new(1, 2, 1)
noobCharacter:AddChild(leftLeg)
local rightLeg = Instance.new("Part")
rightLeg.Name = "Right Leg"
rightLeg.Size = Vector3.new(1, 2, 1)
noobCharacter:AddChild(rightLeg)
noobCharacter.Parent = ServerStorage
end
-- Create noob folder
local noobFolder = Instance.new("Folder")
noobFolder.Name = noobFolderName
noobFolder.Parent = ServerStorage
-- Create NPC walk folder
local npcWalkFolder = Workspace:FindFirstChild(npcWalkFolderName)
if not npcWalkFolder then
npcWalkFolder = Instance.new("Folder")
npcWalkFolder.Name = npcWalkFolderName
npcWalkFolder.Parent = Workspace
end
-- Find walk part, start part, and end part
local walkPart = npcWalkFolder:FindFirstChild(walkPartName)
local startPart = npcWalkFolder:FindFirstChild(startPartName)
local endPart = npcWalkFolder:FindFirstChild(endPartName)
if not walkPart or not startPart or not endPart then
error("One or more required parts not found")
end
-- Clone noob character and move to noob folder
local clonedNoob = noobCharacter:Clone()
clonedNoob.Parent = noobFolder
-- Move noob character to start part
clonedNoob.HumanoidRootPart.CFrame = startPart.CFrame
-- Function to make noob character walk
local function makeNoobWalk()
-- Move noob character to walk part
clonedNoob.HumanoidRootPart.Parent = walkPart
clonedNoob.Humanoid.WalkSpeed = 5
-- Animate noob character walking
local walkAnimation = Instance.new("Animation")
walkAnimation.Name = "WalkAnimation"
walkAnimation.AnimationId = "http://www.roblox.com/asset/?id=180436665"
local animationTrack = clonedNoob.Humanoid:LoadAnimation(walkAnimation)
animationTrack:Play()
-- Move noob character from start part to end part
while (clonedNoob.HumanoidRootPart.Position - endPart.Position).Magnitude > 0.1 do
clonedNoob.HumanoidRootPart.CFrame = clonedNoob.HumanoidRootPart.CFrame:Lerp(endPart.CFrame, 0.05)
wait(0.1)
end
-- Remove noob character
clonedNoob:Destroy()
end
-- Call function to make noob character walk
makeNoobWalk()
How it works:
- The script creates a new character (noob) in ServerStorage if it doesn't already exist.
- It creates a new folder (Noobs Folder) in ServerStorage and moves the noob character to it.
- It finds the walk part, start part, and end part in Workspace.
- It clones the noob character and moves it to the start part.
- It makes the noob character walk on the walk part by setting its HumanoidRootPart parent to the walk part and animating it with a walk animation.
- It moves the noob character from the start part to the end part using a while loop.
- Finally, it removes the noob character when it reaches the end part.
Example use case:
- Create a new part in Workspace and name it "walk".
- Create two new parts in Workspace and name them "Start" and "End".
- Create a new folder in Workspace and name it "NPCWalk Folder".
- Move the "walk", "Start", and "End" parts into the "NPCWalk Folder".
- Run the script.
- The noob character will be created, moved to the start part, and walk on the walk part to the end part.