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

Swords not working overtime?

Asked by 9 years ago
r = game:GetService("RunService") 
ching = false 
sword = script.Parent.Handle 
Tool = script.Parent 
script.Parent.ToolTip = "Base damage: " .. script.Parent.MinDmg.Value .. "-" .. script.Parent.MaxDmg.Value .. " | Critical damage: " .. (script.Parent.CritMagnitude.Value/100).. "x"

function blow(hit) 
if ching == true then return end 
    local humanoid = hit.Parent:FindFirstChild("Human") 
    local vCharacter = game.Players.LocalPlayer.Character
    local vPlayer = game.Players.LocalPlayer
    if humanoid~=nil then 
        ching = true 
        --print("SWORD HIT") 
        tagHumanoid(humanoid, vPlayer) 
        local damage = math.random(script.Parent.MinDmg.Value+math.floor(vPlayer.attributes.Strength.Value/2),script.Parent.MaxDmg.Value+math.floor(vPlayer.attributes.Strength.Value/2))+math.floor(vPlayer.leaderstats.Lvl.Value/5)
        local hitroll = math.random(1, 100)
        local critroll = math.random(1, 100)
        --Hit and critical modifier.
        if hitroll > Game.Workspace.GAME_PROPERTIES.BaseHitChance.Value + (vPlayer.attributes.Dexterity.Value * (Game.Workspace.GAME_PROPERTIES.HitChanceDexMagnitude.Value/100)) then
            damage = 0
        end
        if critroll <= Game.Workspace.GAME_PROPERTIES.BaseCritChance.Value + (vPlayer.attributes.Dexterity.Value * (Game.Workspace.GAME_PROPERTIES.CritChanceDexMagnitude.Value/100)) then
            damage = damage * (script.Parent.CritMagnitude.Value / 100) -- Percentage.
        end
        --Enemy health bar GUI
        if vPlayer.PlayerGui:FindFirstChild("EnemyInfo") ~= nil and humanoid.Health > 0 then
            vPlayer.PlayerGui:FindFirstChild("EnemyInfo").EnemyBar.TickUntilRemove.Value = 75
        else
            GUI = Game.ReplicatedStorage.EnemyInfo:Clone()
            GUI.EnemyBar.Tag.Value = humanoid.Parent
            GUI.Parent = vPlayer.PlayerGui
        end
        --Damages humanoid
        humanoid:TakeDamage(damage) 
        --Floating damage text
        local part = Instance.new("BillboardGui")
        part.Size = UDim2.new(0,50,0,100) 
        part.StudsOffset = Vector3.new(0,2,0)
        local part2 = Instance.new("TextLabel") 
        dt = Game.ReplicatedStorage.DynamicText:Clone()
        part2.Font = "SourceSansBold"
        part2.FontSize = "Size24"
        part2.TextStrokeTransparency = 0
        part2.Size = UDim2.new(1,0,1,0) 
        part2.Position = UDim2.new(0,0,0,0) 
        part2.BackgroundTransparency = 1
        part2.Parent = part 
        dt.Parent = part2
        dt.Disabled = false
        part.Parent = humanoid.Parent.Head
        part.Adornee = part.Parent
        --Shows text depending on conditions. Tells either miss or number.
        if (damage == 0) then 
            part2.TextColor3 = Color3.new(0,0.5,1)
            part2.Text = "Miss!"
        else 
            part2.TextColor3 = Color3.new(1,1,1)
            if critroll <= Game.Workspace.GAME_PROPERTIES.BaseCritChance.Value + (vPlayer.attributes.Dexterity.Value * (Game.Workspace.GAME_PROPERTIES.CritChanceDexMagnitude.Value/100)) then
                part2.TextColor3 = Color3.new(1,1,0)
                part2.FontSize = "Size36"
                part2.Text = ""..damage.."!"
            else
                part2.Text = ""..damage..""
            end
        end 
        wait(.75) 
        ching = false 
        wait(.1) 
        untagHumanoid(humanoid) 
    end 
end 

function tagHumanoid(humanoid, player) 
local creator_tag = Instance.new("ObjectValue") 
creator_tag.Value = player 
creator_tag.Name = "creator" 
creator_tag.Parent = humanoid 
end 

function untagHumanoid(humanoid) 
    if humanoid ~= nil then 
        local tag = humanoid:findFirstChild("creator") 
        if tag ~= nil then 
            tag.Parent = nil 
        end 
    end 
end 

function attack() 
    anim = Tool.Parent.Humanoid:LoadAnimation(script.Parent.Slash)
    anim:Play()
end 

Tool.Enabled = true 

function onActivated() 

    if not Tool.Enabled then return end 

    Tool.Enabled = false 

    local character = Tool.Parent
    local humanoid = character.Humanoid 

    if humanoid == nil then print("Humanoid not found") return end 

    attack() 

    wait(1) 

    Tool.Enabled = true 
end 

function onEquipped() 

end 

script.Parent.Activated:connect(onActivated) 
script.Parent.Equipped:connect(onEquipped) 


connection = sword.Touched:connect(blow)

The swords work fine at first but after a couple minutes they glicth and don't do damage, but they do play the animation

Answer this question