Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mob AI's not working? [closed]

Asked by
Xuxiym 15
9 years ago

I was checking out the files of Guest Quest Online sense BuildIntoGames uncopylocked the place for everyone to take, but the mob AI's won't work properly, some help would be nice.

local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local head = script.Parent:WaitForChild("Head2")
local real_head = script.Parent:WaitForChild("Head")
local linked_sword = script.Parent:WaitForChild("Linked_Sword")
local settings = script.Parent:WaitForChild("Settings")
local events = {}
local damage_sounds = {181268610,181268607,181268605}
local hats = {}


--- animations storage ---

local animation_walk = Instance.new("Animation")
animation_walk.AnimationId = "http://www.roblox.com/asset/?id=180426354"
local running_animation_walk = nil

local animation_attack = Instance.new("Animation")
animation_attack.AnimationId = "http://www.roblox.com/asset/?id=94161088"
local running_animation_attack = nil

--------------------------




function load_hat(id)
local new_hat = game:GetService("InsertService"):LoadAsset(id)
    for i,v in ipairs(new_hat:GetChildren()) do
        if(v.ClassName == "Hat") then
        v.Parent = script.Parent
        end
    end
new_hat:Destroy()
end


Instance.new("ForceField",script.Parent)
--load_hat(hats[math.random(1,#hats)])
    for i = 1,2 do
    wait(0.5)
    humanoid.MaxHealth = settings.Health.Value
    humanoid.Health = settings.Health.Value
    end
script.Parent.ForceField:Destroy()
humanoid.MaxHealth = settings.Health.Value
humanoid.Health = settings.Health.Value




function sound(id,parent,pitch,volume,remove_time)
local sounde = Instance.new("Sound",parent)
game.Debris:AddItem(sounde,remove_time)
sounde.SoundId = "http://www.roblox.com/asset/?id=" .. id
sounde.Pitch = pitch
sounde.Volume = volume
sounde:Play()
return (sounde)
end





function hurt(human)
    if(human) then
        human.Health = human.Health - settings.Damage.Value
        local random_sound_effect = damage_sounds[math.random(1,#damage_sounds)]
        sound(random_sound_effect,human.Parent.Torso,math.random(70,100)/100,1,2)
    end
end




function attack(human)
sound(181268614,linked_sword.Handle,math.random(90,110)/100,1,2)
    if(human.Health ~= 0) then
    local event_keyframe_reached
    running_animation_attack = humanoid:LoadAnimation(animation_attack)
    running_animation_attack:Play()
        event_keyframe_reached = running_animation_attack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
            if (keyframeName == "Hit") then
            hurt(human)

            elseif(keyframeName == "End") then
            running_animation_attack:Stop()
            event_keyframe_reached:disconnect()
            end
        end)
    end
end




function walk(operation)
    if(operation == true) then
    running_animation_walk = humanoid:LoadAnimation(animation_walk)
    running_animation_walk:Play()


    elseif(operation == false) then
    running_animation_walk:Stop()
    humanoid:MoveTo(torso.Position,torso)
    end
end











function follow(plr,char,dist)
    if(plr and char) then
        if(dist <= settings.Attack_Distance.Value and char:FindFirstChild("Humanoid")) then
        walk(false)
        attack(char.Humanoid)


        elseif(char:FindFirstChild("Humanoid") and dist > settings.Attack_Distance.Value) then
        walk(true)
        script.Parent.Humanoid:MoveTo(char.HumanoidRootPart.Position,char.HumanoidRootPart)
        end

    else
    walk(false)
    end
end














while wait() do
local dist = 45
local target = nil
local target_char = nil
    for i,v in ipairs(game.Players:GetChildren()) do
    wait()
        if(v.ClassName == "Player") then
            if(v.Character) then
                if(v.Character:FindFirstChild("HumanoidRootPart")) then
                    if((v.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < dist) then
                    dist = (v.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
                    target = v
                    target_char = v.Character
                    end
                end
            end
        end
    end
follow(target,target_char,dist)
wait(settings.Fire_Speed.Value)
end








0
Forgot to say, got the animations working but it's not attacking. Xuxiym 15 — 9y
0
So you want us to fix his broken scripts for your own pleasure? No, thank you. Marios2 360 — 9y

Closed as Too Broad by Marios2, 1waffle1, and User#5978

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?