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

plr.CharacterAdded:Connect(function(ctr) not functioning?

Asked by 5 years ago
Edited 5 years ago
plr = game.Players.LocalPlayer
UIS = game:GetService("UserInputService")
punch = false
damage = false
dmg = plr:WaitForChild("Stats"):WaitForChild("Strength")
health = dmg.Value
plr.CharacterAdded:Connect(function(ctr)
    local leftpunch = Instance.new("Animation")
    leftpunch.AnimationId = "rbxassetid://2523553984"
    leftpunchtrack = ctr:WaitForChild("Humanoid"):LoadAnimation(leftpunch)
    local leftkick = Instance.new("Animation")
    leftkick.AnimationId = "rbxassetid://2714423586"
    leftkicktrack = ctr:FindFirstChild("Humanoid"):LoadAnimation(leftkick)
    local rightkick = Instance.new("Animation")
    rightkick.AnimationId = "rbxassetid://2714442073"
    rightkicktrack = ctr:WaitForChild("Humanoid"):LoadAnimation(rightkick)
    local leftkick = Instance.new("Animation")
    leftkick.AnimationId = "rbxassetid://2714423586"
    leftkicktrack = ctr:WaitForChild("Humanoid"):LoadAnimation(leftkick)
    rightpunch = Instance.new("Animation")
    rightpunch.AnimationId = "rbxassetid://2714449029"
    rightpunchtrack = ctr:WaitForChild("Humanoid"):LoadAnimation(rightpunch)
    thing = {leftpunchtrack, rightpunchtrack, leftkicktrack, rightkicktrack}
    UIS.InputBegan:Connect(function(key ,process)
        print(process)
        if process == false and key.KeyCode == Enum.KeyCode.E then
            print('clicked e')
            if punch == false then
                print("PUNCH")
                punch = true
                an = thing[math.random(1, #thing)]
                an:Play()
                plr:WaitForChild("Stats"):WaitForChild("Strength").Value = plr.Stats.Strength.Value + 5
                print("played")
                damage = true
                wait(0.5)
                punch = false
            end
        end
    end)
    ctr:WaitForChild("Left Arm").Touched:Connect(function(hit)--i need left arm to be what animation it plays
    attack = hit.Parent:FindFirstChild("Humanoid")
    if attack and damage and punch then
        attack:TakeDamage(health)
    end
    end)

end)

dmg.Changed:Connect(function(Value)
    health = Value
end)

When I test sometimes it prints and it does what it's supposed to do. But sometimes it's not even printing anything and not playing animations. Also in this question i want to include that in line 41 i want the ctr:WaitForChild("Left Arm") to be which ever animation it plays meaning if i do right punch it is Right Arm(r6).

0
Also it starts working after I reset. HappyTimIsHim 652 — 5y
0
i realized that the CharacterAdded function runs sometimes but sometimes not HappyTimIsHim 652 — 5y

Answer this question