I'm trying to make a combat system. And I just noticed that whenever a player does an attack, other players "Attackings" also turns to True even without them pressing the keys.
Server Script:
game.Players.PlayerAdded:Connect(function(player)
local player = player
local debounce = false
--these are the "Attackings"
local leftPunching = false
local rightPunching = false
local leftKicking = false
local rightKicking = false
local function leftPunch()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftFist = character:WaitForChild("Left Arm")
leftPunching = true
wait(1)
leftPunching = false
leftFist.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and leftPunching then
if not debounce then
debounce = true
humanoid:TakeDamage(10)
wait(.5)
debounce = false
end
end
end)
end
local function rightPunch()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightFist = character:WaitForChild("Right Arm")
rightPunching = true
wait(1)
rightPunching = false
rightFist.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and rightPunching then
if not debounce then
debounce = true
humanoid:TakeDamage(10)
wait(.5)
debounce = false
end
end
end)
end
local function leftKick()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftFoot = character:WaitForChild("Left Leg")
leftKicking = true
wait(1)
leftKicking = false
leftFoot.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and leftKicking then
if not debounce then
debounce = true
humanoid:TakeDamage(20)
wait(.5)
debounce = false
end
end
end)
end
local function rightKick()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightFoot = character:WaitForChild("Right Leg")
rightKicking = true
wait(1)
rightKicking = false
rightFoot.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and rightKicking then
if not debounce then
debounce = true
humanoid:TakeDamage(20)
wait(.5)
debounce = false
end
end
end)
end
game.ReplicatedStorage.RemoteLP.OnServerEvent:Connect(leftPunch)
game.ReplicatedStorage.RemoteRP.OnServerEvent:Connect(rightPunch)
game.ReplicatedStorage.RemoteLK.OnServerEvent:Connect(leftKick)
game.ReplicatedStorage.RemoteRK.OnServerEvent:Connect(rightKick)
end)
Client:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local LPcooldown = false
local RPcooldown = false
local LKcooldown = false
local RKcooldown = false
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Q then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftPunch = script.LeftPunch
local leftPunchTrack = humanoid:LoadAnimation(leftPunch)
if not LKcooldown then
LKcooldown = true
leftPunchTrack:Play()
wait(1)
LKcooldown = false
end
game.ReplicatedStorage.RemoteLP:FireServer()
end
if input.KeyCode == Enum.KeyCode.E then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightPunch = script.RightPunch
local rightPunchTrack = humanoid:LoadAnimation(rightPunch)
if not RPcooldown then
RPcooldown = true
rightPunchTrack:Play()
wait(1)
RPcooldown = false
end
game.ReplicatedStorage.RemoteRP:FireServer()
end
if input.KeyCode == Enum.KeyCode.Z then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftKick = script.LeftKick
local leftKickTrack = humanoid:LoadAnimation(leftKick)
if not LKcooldown then
LKcooldown = true
leftKickTrack:Play()
wait(1)
LKcooldown = false
end
game.ReplicatedStorage.RemoteLK:FireServer()
end
if input.KeyCode == Enum.KeyCode.C then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightKick = script.RightKick
local rightKickTrack = humanoid:LoadAnimation(rightKick)
if not RKcooldown then
RKcooldown = true
rightKickTrack:Play()
wait(1)
RKcooldown = false
end
game.ReplicatedStorage.RemoteRK:FireServer()
end
end)
So I modify it a bit, and now the damage is completely gone. :|
Server Script:
game.Players.PlayerAdded:Connect(function(player)
local player = player
local debounce = false
local function leftPunch()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftFist = character:WaitForChild("Left Arm")
leftFist.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not debounce then
debounce = true
humanoid:TakeDamage(10)
wait(.5)
debounce = false
end
end
end)
end
local function rightPunch()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightFist = character:WaitForChild("Right Arm")
rightFist.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not debounce then
debounce = true
humanoid:TakeDamage(10)
wait(.5)
debounce = false
end
end
end)
end
local function leftKick()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftFoot = character:WaitForChild("Left Leg")
leftFoot.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not debounce then
debounce = true
humanoid:TakeDamage(20)
wait(.5)
debounce = false
end
end
end)
end
local function rightKick()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightFoot = character:WaitForChild("Right Leg")
rightFoot.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not debounce then
debounce = true
humanoid:TakeDamage(20)
wait(.5)
debounce = false
end
end
end)
end
game.ReplicatedStorage.RemoteLP.OnServerEvent:Connect(leftPunch)
game.ReplicatedStorage.RemoteRP.OnServerEvent:Connect(rightPunch)
game.ReplicatedStorage.RemoteLK.OnServerEvent:Connect(leftKick)
game.ReplicatedStorage.RemoteRK.OnServerEvent:Connect(rightKick)
end)
Client:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local LPcooldown = false
local RPcooldown = false
local LKcooldown = false
local RKcooldown = false
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Q then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftPunch = script.LeftPunch
local leftPunchTrack = humanoid:LoadAnimation(leftPunch)
local leftPunching = false
if not LPcooldown then
LPcooldown = true
leftPunchTrack:Play()
wait(1)
LPcooldown = false
end
leftPunching = true
wait(1)
leftPunching = false
if leftPunching then
game.ReplicatedStorage.RemoteLP:FireServer()
end
end
if input.KeyCode == Enum.KeyCode.E then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightPunch = script.RightPunch
local rightPunchTrack = humanoid:LoadAnimation(rightPunch)
local rightPunching = false
if not RPcooldown then
RPcooldown = true
rightPunchTrack:Play()
wait(1)
RPcooldown = false
end
rightPunching = true
wait(1)
rightPunching = false
if rightPunching then
game.ReplicatedStorage.RemoteRP:FireServer()
end
end
if input.KeyCode == Enum.KeyCode.Z then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leftKick = script.LeftKick
local leftKickTrack = humanoid:LoadAnimation(leftKick)
local leftKicking = false
if not LKcooldown then
LKcooldown = true
leftKickTrack:Play()
wait(1)
LKcooldown = false
end
leftKicking = true
wait(1)
leftKicking = false
if leftKicking then
game.ReplicatedStorage.RemoteLK:FireServer()
end
end
if input.KeyCode == Enum.KeyCode.C then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rightKick = script.RightKick
local rightKickTrack = humanoid:LoadAnimation(rightKick)
local rightKicking = false
if not RKcooldown then
RKcooldown = true
rightKickTrack:Play()
wait(1)
RKcooldown = false
end
rightKicking = true
wait(1)
rightKicking = false
if rightKicking then
game.ReplicatedStorage.RemoteRK:FireServer()
end
end
end)
