#sword issues

13 messages · Page 1 of 1 (latest)

idle dragon
#
-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClonedHurtbox = game.ReplicatedStorage.SmallHurtbox:Clone()
game:GetService('RunService').Stepped:Wait()
-- Variables
local sword = script.Parent
local Player = script.Parent.Parent.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local Animator: Animator = Humanoid:WaitForChild("Animator")
local Debounce = {}
local COOLDOWN_DURATION = 1.30
-- Animations
-- Animation Stuff
local function CreateAnimationTrack(ID)
    local AnimFile = Instance.new("Animation")
    AnimFile.AnimationId = ID
    local AnimTrack = Animator:LoadAnimation(AnimFile)
    return AnimTrack
end

local SwordIdle = CreateAnimationTrack("rbxassetid://14850115859")
local SwordSwing1 = CreateAnimationTrack("rbxassetid://14850117022")
local SwordSwing2 = CreateAnimationTrack("rbxassetid://14850118030")
local SwordSwing3 = CreateAnimationTrack("rbxassetid://14850119287")
local CrouchEntry = CreateAnimationTrack("rbxassetid://14776702318")
local CrouchExit = CreateAnimationTrack("rbxassetid://14776704918")
local ProneCrawl = CreateAnimationTrack("rbxassetid://14777151648")
local ProneIdle = CreateAnimationTrack("rbxassetid://14777127384")
local SprintAnim = CreateAnimationTrack("rbxassetid://14827395801")
local ClimbAnim = CreateAnimationTrack(("rbxassetid://14827395801"))

local function Play(Track: AnimationTrack)
    if not Track.IsPlaying then Track:Play() end
end

local function Stop(Track: AnimationTrack)
    if Track.IsPlaying then Track:Stop() end
end

if Humanoid.MoveDirection.Magnitude < 1 then
    for _, idk in {ProneIdle, ProneCrawl, CrouchExit, CrouchEntry, ClimbAnim} do
        if idk.IsPlaying then
            return
        end
    end
        Play(SwordIdle)
    else
        Stop(SwordIdle)
    end

sword.Activated:Connect(function()
    for _, idk in {ProneIdle, ProneCrawl, CrouchExit, CrouchEntry, ClimbAnim, SprintAnim} do
        if idk.IsPlaying then
            return
        end
    end
    function Swing()
        local AnimationChosen = math.random(1,3)
        if AnimationChosen == 1 then
            Play(SwordSwing1)
        elseif     AnimationChosen == 2 then
            Play(SwordSwing2)
        elseif     AnimationChosen == 3 then
            Play(SwordSwing3)    
        end
        ClonedHurtbox:Clone()
        ClonedHurtbox.Parent = Player
end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        Swing()
    end
end)

need it to place a hitbox infront of the player when you swing but it wont
also cant get it to have a cooldown, or not play when other animations are playing

idle dragon
#

updated;

-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SmallHurtbox = game.ReplicatedStorage.SmallHurtbox
game:GetService('RunService').Stepped:Wait()
-- Variables
local Players = game.Players
local sword = script.Parent
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local Animator: Animator = Humanoid:WaitForChild("Animator")
local Debounce = {}
local COOLDOWN_DURATION = 1.30
-- Animations
-- Animation Stuff
local function CreateAnimationTrack(ID)
    local AnimFile = Instance.new("Animation")
    AnimFile.AnimationId = ID
    local AnimTrack = Animator:LoadAnimation(AnimFile)
    return AnimTrack
end

local SwordIdle = CreateAnimationTrack("rbxassetid://14850115859")
local SwordSwing1 = CreateAnimationTrack("rbxassetid://14850117022")
local SwordSwing2 = CreateAnimationTrack("rbxassetid://14850118030")
local SwordSwing3 = CreateAnimationTrack("rbxassetid://14850119287")
local CrouchEntry = CreateAnimationTrack("rbxassetid://14776702318")
local CrouchExit = CreateAnimationTrack("rbxassetid://14776704918")
local ProneCrawl = CreateAnimationTrack("rbxassetid://14777151648")
local ProneIdle = CreateAnimationTrack("rbxassetid://14777127384")
local SprintAnim = CreateAnimationTrack("rbxassetid://14827395801")
local ClimbAnim = CreateAnimationTrack(("rbxassetid://14827395801"))

local function Play(Track: AnimationTrack)
    if not Track.IsPlaying then Track:Play() end
end

local function Stop(Track: AnimationTrack)
    if Track.IsPlaying then Track:Stop() end
end

if Humanoid.MoveDirection.Magnitude < 1 then
    for _, idk in {ProneIdle, ProneCrawl, CrouchExit, CrouchEntry, ClimbAnim} do
        if idk.IsPlaying then
            return
        end
    end
        Play(SwordIdle)
    else
        Stop(SwordIdle)
    end

sword.Activated:Connect(function()
    function Swing()
        if Debounce == true then return end
        local function StopAnimation(Humanoid, AnimationName)
            local Animator = Humanoid.Animator or Humanoid:WaitForChild("Animator")
            for _, AnimationTrack in pairs(Animator:GetPlayingAnimations()) do
                if AnimationTrack.Name == AnimationName then
                    AnimationTrack:Stop()
                end
            end
        end
        local AnimationChosen = math.random(1,3)
        if AnimationChosen == 1 then
            Play(SwordSwing1)
        elseif     AnimationChosen == 2 then
            Play(SwordSwing2)
        elseif     AnimationChosen == 3 then
            Play(SwordSwing3)    
        end
        SmallHurtbox:Clone().Parent = Player
        Debounce = true    
        task.delay(COOLDOWN_DURATION, function() -- clear memory - if you store a timer value, the key will never get cleaned up when humanoid dies and actually keeps a reference to it so garbage collection can't clean it
            Debounce = nil -- clear memory
        end)
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        Swing()
    end
end)
idle dragon
#
-- Variables and Services
local tool = script.Parent
local Debounce = false
local COOLDOWN_DURATION = 1.30
local MuchachoHitbox = require(game.ServerStorage.MuchachoHitbox)
local Player = tool.Parent.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
game:GetService('RunService').Stepped:Wait()
print("Variables loaded.")
--- Animation
local function CreateAnimationTrack(ID)
    local AnimFile = Instance.new("Animation")
    AnimFile.AnimationId = ID
    local AnimTrack = Animator:LoadAnimation(AnimFile)
    return AnimTrack
end

local SwordIdle = CreateAnimationTrack("rbxassetid://14850115859")
local SwordSwing1 = CreateAnimationTrack("rbxassetid://14850117022")
local SwordSwing2 = CreateAnimationTrack("rbxassetid://14850118030")
local SwordSwing3 = CreateAnimationTrack("rbxassetid://14850119287")
local AllAnims = {SwordSwing1, SwordSwing2, SwordSwing3}


local function Play(Track: AnimationTrack)
    if not Track.IsPlaying then Track:Play() end
end

local function Stop(Track: AnimationTrack)
    if Track.IsPlaying then Track:Stop() end
end
print("Animations loaded.")
--- Code
local function Swing()
    print("Swing started.")
    local character = tool.Parent

    local Hitbox = MuchachoHitbox.CreateHitbox()
    Hitbox.Size = Vector3.new(6,6,6)
    Hitbox.CFrame = character.HumanoidRootPart
    Hitbox.Offset = CFrame.new(0,0,-2)

    Hitbox.Touched:Connect(function()
        print("The sword has hit a target.")
        Humanoid:TakeDamage(math.random(10,25))
    end)
    local AnimationIndexChosen = math.random(1,3)
    local AnimationChosen = AllAnims[AnimationIndexChosen]
    AnimationChosen:Play()

    print("Chosen animation.")
    AnimationChosen:GetMarkerReachedSignal("SwingBegin")
    Hitbox:Start()
    AnimationChosen:GetMarkerReachedSignal("SwingEnd")
    Hitbox:Stop()
end
print("The entire script has loaded.")

tool.Activated:Connect(function()
    if Debounce == true then return end
    Debounce = true
    Swing() 
    wait(1.30)
    Debounce = false
end)

new updated code. hitboxes wont appear though

idle dragon
#
-- Variables and Services
local tool = script.Parent
local Debounce = false
local COOLDOWN_DURATION = 1.30
local MuchachoHitbox = require(game.ServerStorage.MuchachoHitbox)
local Player = tool.Parent.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local IsSprinting = Player.StarterPlayer.StarterCharacterScripts.SprintBool
local IsProne = Player.StarterPlayer.StarterCharacterScripts.ProneBool

game:GetService('RunService').Stepped:Wait()
print("Variables loaded.")
--- Animation
local function CreateAnimationTrack(ID)
    local AnimFile = Instance.new("Animation")
    AnimFile.AnimationId = ID
    local AnimTrack = Animator:LoadAnimation(AnimFile)
    return AnimTrack
end

local SwordIdle = CreateAnimationTrack("rbxassetid://14850115859")
local SwordSwing1 = CreateAnimationTrack("rbxassetid://14850117022")
local SwordSwing2 = CreateAnimationTrack("rbxassetid://14850118030")
local SwordSwing3 = CreateAnimationTrack("rbxassetid://14850119287")
local AllAnims = {SwordSwing1, SwordSwing2, SwordSwing3}


local function Play(Track: AnimationTrack)
    if not Track.IsPlaying then Track:Play() end
end

local function Stop(Track: AnimationTrack)
    if Track.IsPlaying then Track:Stop() end
end
print("Animations loaded.")
--- Code
local function Swing()
    print("Swing started.")

    local Hitbox = MuchachoHitbox.CreateHitbox()
    Hitbox.Size = Vector3.new(6,6,6)
    Hitbox.CFrame = Character.Humanoid
    Hitbox.Offset = CFrame.new(0,0,-2)

    Hitbox.Touched:Connect(function()
        print("The sword has hit a target.")
        Humanoid:TakeDamage(math.random(10,25))
    end)
    local ChosenAnim = math.random(1,3)
    if ChosenAnim == 1 then
        SwordSwing1:Play()
        print("Chosen animation 1.")
        SwordSwing1:GetMarkerReachedSignal("SwingBegin")
        Hitbox:Start()
        SwordSwing1:GetMarkerReachedSignal("SwingEnd")
        Hitbox:Stop()
    elseif ChosenAnim == 2 then
        SwordSwing2:Play()
        print("Chosen animation 2.")
        SwordSwing2:GetMarkerReachedSignal("SwingBegin")
        Hitbox:Start()
        SwordSwing2:GetMarkerReachedSignal("SwingEnd")
        Hitbox:Stop()
    elseif ChosenAnim == 3 then
        SwordSwing3:Play()
        print("Chosen animation 3.")
        SwordSwing3:GetMarkerReachedSignal("SwingBegin")
        Hitbox:Start()
        SwordSwing3:GetMarkerReachedSignal("SwingEnd")
        Hitbox:Stop()
    end
end
print("The entire script has loaded.")

tool.Activated:Connect(function()
    if Debounce == true then return end
    Debounce = true
    Swing() 
    wait(1.30)
    Debounce = false
end)

still wont work

earnest mauve
#

bro

#

ur using getmarkerreachedsignal wrong

#

ur starting the hitbox and ending it automatically

#

@idle dragon

idle dragon
#

fuck

#

at least its something simple 😭

earnest mauve
# idle dragon ```lua -- Variables and Services local tool = script.Parent local Debounce = fal...
local Swinging = false

local function EnableHitbox()
  Hitbox:Start()
end

local function DisableHitbox()
  Swinging = false
  Hitbox:End()
end

local Anims = {SwordSwing1,SwordSwing2,SwordSwing3}

for _,Anim in Anims do
  Anim:GetMarkerReachedSignal("SwingBegin"):Connect(EnableHitbox)
  Anim:GetMarkerReachedSignal("SwingEnd"):Connect(DisableHitbox)
end

local OnAnim = 1

local function Swing()
  if Swinging then return end
  Swinging = true
  local Anim = Anims[OnAnim]
  Anim:Play()
  OnAnim = OnAnim < #Anims and OnAnim + 1 or 1
end

tool.Activated:Connect(Swing)
#

this the most help ur getting from me, good luck