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")

4 comments
Do the animations make you punch?
Hmm probably make another parameter that checks if the player/NPC that you are fighting has a Humanoid
What kind of script is this and where does it go?
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