Why doesn't my boss battle work? I used Body Gyro and this script:
local Humanoid = script.Parent:WaitForChild("Humanoid")
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local WalkRange = 20
local LavaBallSpeed = 45
local Closest = nil
spawn(function()
while true do
wait()
if Closest _= nil then
HumanoidRootPart.BodyGyro.CFrame = CFrame.new(HumanoidRootPart.Position,Vector3.new(Closest.Character.HumanoidRootPart.Position.X,HumanoidRootPart.Position.Y,Closest.Character.HumanoidRootPart.Position.Z))
end
end
end)
while true do
wait(2)
local RandomValue = math.random(0,10)
local List = ()
for i,v in pairs(game.Players:GetChildren()) do
if v. and v.Character then
local Distance = (HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude
table.insert(List,(v,Distance))
end
end
table.sort(List,function(A,B)
return A[2] <= B[2]
end)
if #List >= 1 then
Closest = List[1][1]
if RandomValue > 0 and RandomValue < 6 then
local RandomWalkPosition = Vector3.new(math.random(-WalkRange,WalkRange),0,math.random(-WalkRange,WalkRange))
Humanoid:MoveTo(HumanoidRootPart.Position+RandomWalkPosition)
else
local Lavaball = Instance.new("Part")
Lavaball.Anchored = false
Lavaball.Shape = "Ball"
Lavaball.Size = Vector3.new(4,4,4)
Lavaball.TopSurface = Enum.SurfaceType.Smooth
Lavaball.BottomSurface = Enum.SurfaceType.Smooth
Lavaball.Material = Enum.Material.CorrodedMetal
Lavaball.BrickColor = BrickColor.new("Maroon")
Lavaball.CFrame = HumanoidRootPart.CFrame*CFrame.new(0,0,-10)
Lavaball.Parent = workspace
Lavaball.CanCollide = false
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(100000,100000,100000)
local Origin = HumanoidRootPart.Position
BV.Velocity = (List[1][1].Character.HumanoidRootPart.Position - Origin).unit * LavaBallSpeed
BV.Parent = Lavaball
spawn(function()
wait(1)
Lavaball.Touched:Connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(25)
end
Lavaball:Destroy()
end)
end)
wait(2)
end
end
end
(At my game on the page it says "This game doesn't function" something like that.) I visit the website but still don't know how to fix my script. Can someone help me with this or reply with the script that works?
Thank you so much!