Ball
To create a sphere in Roblox, you can use the Part
object and set its Shape
property to "Ball"
. Here’s an example of how you can do this:
local sphere = Instance.new("Part")
sphere.Shape = "Ball"
sphere.Size = Vector3.new(1, 1, 1) -- sets the size of the sphere
sphere.Parent = game.Workspace -- adds the sphere to the game world
This will create a sphere with a diameter of 1 unit and add it to the Workspace
object. You can adjust the size of the sphere by changing the Size
property, and you can also adjust its position and orientation by changing its CFrame
property.
Person
To create a person in Roblox, you can use the Model
object and add Humanoid
and CharacterMesh
objects to it. Here’s an example of how you can do this:
local character = Instance.new("Model")
character.Name = "Character"
local humanoid = Instance.new("Humanoid")
humanoid.Parent = character
local head = Instance.new("Part")
head.Name = "Head"
head.Size = Vector3.new(1, 1, 1)
head.Parent = character
local torso = Instance.new("Part")
torso.Name = "Torso"
torso.Size = Vector3.new(1, 2, 1)
torso.Parent = character
local lArm = Instance.new("Part")
lArm.Name = "Left Arm"
lArm.Size = Vector3.new(1, 2, 1)
lArm.Parent = character
local rArm = Instance.new("Part")
rArm.Name = "Right Arm"
rArm.Size = Vector3.new(1, 2, 1)
rArm.Parent = character
local lLeg = Instance.new("Part")
lLeg.Name = "Left Leg"
lLeg.Size = Vector3.new(1, 2, 1)
lLeg.Parent = character
local rLeg = Instance.new("Part")
rLeg.Name = "Right Leg"
rLeg.Size = Vector3.new(1, 2, 1)
rLeg.Parent = character
local characterMesh = Instance.new("CharacterMesh")
characterMesh.Parent = character
character.Parent = game.Workspace
This will create a character with a head, torso, arms, and legs, and add it to the Workspace
object. You can adjust the size and shape of the parts by changing their Size
and Shape
properties. You can also add other objects to the character, such as a Hat
, Shirt
, or Pants
, by creating them and setting their Parent
property to the character model.
Enemy
To create an enemy in Roblox, you can use the Model
object and add a Humanoid
and CharacterMesh
to it. You can then add a script to the enemy that controls its behavior, such as chasing the player or attacking when the player gets within a certain range.
Here’s an example of how you can create an enemy model and add a script to it:
-- create the enemy model
local enemy = Instance.new("Model")
enemy.Name = "Enemy"
local humanoid = Instance.new("Humanoid")
humanoid.Parent = enemy
local characterMesh = Instance.new("CharacterMesh")
characterMesh.Parent = enemy
-- add a script to the enemy that makes it chase the player
local script = Instance.new("Script")
script.Parent = enemy
script.Code = [[
while true do
-- find the player
local player = game.Players:GetPlayerFromCharacter(script.Parent.Humanoid.Parent)
-- move towards the player
if player then
script.Parent.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
end
wait(1)
end
]]
enemy.Parent = game.Workspace
This will create an enemy model with a Humanoid
and CharacterMesh
, and a script that makes it chase the player. You can adjust the enemy’s behavior by modifying the code in the script.
Here’s an example of how you can modify the script to make the enemy chase the player and jump around:
local enemy = Instance.new("Model")
enemy.Name = "Enemy"
local humanoid = Instance.new("Humanoid")
humanoid.Parent = enemy
local characterMesh = Instance.new("CharacterMesh")
characterMesh.Parent = enemy
local script = Instance.new("Script")
script.Parent = enemy
script.Code = [[
while true do
-- find the player
local player = game.Players:GetPlayerFromCharacter(script.Parent.Humanoid.Parent)
-- move towards the player and jump around
if player then
local toPlayer = player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position
local distance = toPlayer.Magnitude
-- jump if the player is far away
if distance > 10 then
script.Parent.Humanoid.Jump = true
end
script.Parent.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
end
wait(1)
end
]]
enemy.Parent = game.Workspace
This script will make the enemy chase the player and jump around if the player is more than 10 units away. You can adjust the distance at which the enemy starts jumping by changing the value of distance
.
Leave a Reply