I am trying to make an punch script for this game. I want the punch to change every time you click. For example I click 1 and it plays a right hand punch. But if I click 1 time then right after click another time I want it to play a left hand punch. This script I made does what I want except after you do it once it doesn't work again.
local player = game.Players.LocalPlayer
local db = true
local damaged = false
local UserInputService = game:GetService("UserInputService")
local combo = 0
local Punch1 = Instance.new("Animation")
Punch1.AnimationId = "http://www.roblox.com/asset/?id=5943464571"
local Punch2 = Instance.new("Animation")
Punch2.AnimationId ="http://www.roblox.com/asset/?id=5943982783"
game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not db and not damaged and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
damaged = true
game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
end
end
end)
local function onInputBegan(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and db and combo == 0 then
db = false
local PlayFirstPunch = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(Punch1)
PlayFirstPunch:Play()
wait(0.8)
damaged = false
db = true
combo = 1
UserInputService.InputBegan:Connect(onInputBegan)
elseif
input.UserInputType == Enum.UserInputType.MouseButton1 and db and combo == 1 then
db = false
local PlaySecondPunch = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(Punch2)
PlaySecondPunch:Play()
wait(0.8)
damaged = false
db = true
combo = 2
end
end
UserInputService.InputBegan:Connect(onInputBegan)

1 comment
Thanks!