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

How would you make it so the combat script does damage?

Asked by 7 years ago

I'm trying to make a combat script but since i'm just now learning how to script i can't figure it out, Heres the script im working with:

player = game.Players.LocalPlayer.Character
cooldown = 1 --Put amount of seconds for cooldown to last.
db = false

function onKeyPress(actionName, userInputState, inputObject)
    local Combat = math.random(1,4)
    if userInputState == Enum.UserInputState.Begin then
        if db == false then 
        db = true
        --your code
        if Combat == 1 then
        print("Loading First Punch")
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=906039050"
        local animTrack = player.Humanoid:LoadAnimation(animation)
        animTrack:Play()
        wait(cooldown)
        db = false
        end
        if Combat == 2 then
        print("Loading Second Punch")
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=913285256"
        local animTrack = player.Humanoid:LoadAnimation(animation)
        animTrack:Play()
        wait(cooldown)
        db = false
        end
        if Combat == 3 then
        print("Loading Kick")
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=913413359"
        local animTrack = player.Humanoid:LoadAnimation(animation)
        animTrack:Play()
        wait(cooldown)
        db = false
        end
        if Combat == 4 then
        print("Loading Side Kick")
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=913433576"
        local animTrack = player.Humanoid:LoadAnimation(animation)
        animTrack:Play()
        wait(cooldown)
        db = false
        end
    end
    end
    end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, "r")
0
Do the animations make you punch? Bluemonkey132 194 — 7y
0
Hmm probably make another parameter that checks if the player/NPC that you are fighting has a Humanoid saSlol2436 716 — 7y
0
What kind of script is this and where does it go? ScrappyFriend77 34 — 7y
0
For the db part you should've done if db == false then db = true --code here -- end wait() if db == true then db = false end saSlol2436 716 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

If I understand what you're trying to do correctly...

You can make it so whatever body part the animation is using when that is touched the person that touched it gets damaged. For example, let's say the first punch used your left arm.

You could use the following script to deal damage if this script was enabled inside the arm (or player)

-- If you're putting the script in the arm just use script.Parent, otherwise use script.Parent:FindFirstChild("Left Arm"), but let's say it's in the arm

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent.Name = script.Parent.Parent.Name then
            return
        else
            hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 10
        end
    end
end

"hit.Parent:FindFirstChild("Humanoid")" Checks to see if what is hit has a humanoid (so a player or whatever else)

"if hit.Parent.Name = script.Parent.Parent.Name" Makes sure that you don't damage yourself

"hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 10" Removes health, 10 is the amount of health lost

Tell me if this doesn't work, I haven't tried it. I suggest using a debounce so that you're not hitting them 6 times and doing 60 damage instead of once and 10 damage. If you need help with debounce, tell me. Also, if you're planning on using R15, you are going to have to change the "Left Arm" to whatever parts R15 use...

0
dont worked :( darkzerobits 92 — 6y
Ad

Answer this question