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

Mob Will Hit once, Then wont hurt?

Asked by 8 years ago

So... This may sound complicated but, I've scripted this Mob and it attacks you etc... But when it goes to attack you.. it doesnt do anything but play the hit animation once but never hurts the player... any ideas? I'm trying to explain this the best i can, If you need more information. Just ask me! :) heres the script code:

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=361958918"
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
game:GetService("ContentProvider"):Preload(sounde.SoundId)
sounde.Pitch = pitch
sounde.Volume = volume
sounde:Play()
return (sounde)
end





function hurt (human)
    if(human) then
        if(human.Health ~= 0 and human.Parent:FindFirstChild("Torso")) 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
end




function attack (human)
game:GetService("ContentProvider"):Preload(animation_attack.AnimationId)
sound(181268614,linked_sword.Handle,math.random(90,110)/100,1,2)
    if(running_animation_attack == nil and 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()
            running_animation_attack = nil
            event_keyframe_reached:disconnect()
            end
        end)

    repeat wait(0.05) until running_animation_attack == nil
    end
end




function walk(operation)
game:GetService("ContentProvider"):Preload(animation_walk.AnimationId)
    if(operation == true and running_animation_walk == nil) then
    running_animation_walk = humanoid:LoadAnimation(animation_walk)
    running_animation_walk:Play()


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





function loot_player_items(stat_holder)   --- give a stat_holder and you will have a chance of getting loot
local looted = 0
    if(stat_holder:FindFirstChild("Inventory")) then
        for i,v in ipairs(settings.Possible_Items:GetChildren()) do
        wait()
            if(looted < 3.1 and math.random(0,10000) < (v.Value*100)) then
            stat_holder.Inventory.Value = stat_holder.Inventory.Value .. ":" .. v.Name .. ":"
            looted = looted + 1

            elseif(looted > 1.9) then
            break
            end
        end
    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






events[#events + 1] = humanoid.Died:connect(function()
sound(12222242,head,1.1,0.8,2)
real_head.Surprise:Destroy()
animation_walk:Destroy()
animation_attack:Destroy()
    for i,v in ipairs(humanoid:GetChildren()) do    ---- Giving players items and gold, rewarding
        if(game.ServerStorage:FindFirstChild(v.Name .. "Stats")) then
        local stat_holder = game.ServerStorage:FindFirstChild(v.Name .. "Stats")
            if(stat_holder:FindFirstChild("Gold")) then
            stat_holder.Gold.Value = stat_holder.Gold.Value + settings.Gold.Value
            end
            if(stat_holder:FindFirstChild("EXP")) then
            stat_holder.EXP.Value = stat_holder.EXP.Value + settings.EXP.Value
            end
            if(stat_holder:FindFirstChild("ClanPoints")) then
            stat_holder.ClanPoints.Value = stat_holder.ClanPoints.Value + settings.Clan_Points.Value
            end
        loot_player_items(stat_holder)
        end
    end  --- done rewarding players
game.Debris:AddItem(script.Parent,3.5)
    for i = 1,#events do
    events[i]:disconnect()
    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

1
I have to say now, the way your script is organised actually makes it more difficult to follow than you'd appreciate. Some people might disagree with me, that's fine. I'm just telling you that it's harder to look backwards through your script because there's a lot of looking ahead to do with no info of where stuff is going wrong, to determine where stuff is going wrong. PlsNoDiscrimination 0 — 8y
0
I've just re-read my script.. and my guess is this is where the problem is.. from 079 - 099 MrCheezeSteak 0 — 8y
0
I think.. Its something to do with the repeat on line 97 did some Print tests etc.. It doesnt print after the repeat.. any ideas? MrCheezeSteak 0 — 8y
0
Any errors? Shawnyg 4330 — 8y
0
no errors MrCheezeSteak 0 — 8y

Answer this question