I’m trying to make a punching script where you press F to punch. The script works, but if you stand next to somebody and your arm touches them it’ll still deal damage.
--ServerScriptService Script
local punchdb = {}
-- Punchdb is a antiexploit thing for if a remotevent is being fired too quickly.
local punch = game:GetService("ReplicatedStorage"):WaitForChild("PunchEvent")
punch.OnServerEvent:Connect(function(player)
if punchdb[tostring(player.UserId)] == nil then
punchdb[tostring(player.UserId)] = false
local debounce = false
local PunchEvent = game:GetService("ReplicatedStorage")["PunchEvent"]
PunchEvent.OnServerEvent:Connect(function(plr,Touch)
plr.Character.RightHand.Touched:connect(function(hit)
if hit.Parent ~= plr.Character then
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
local dividedby =( plr.leaderstats.Strength.Value / 5 ) + 5
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - dividedby
wait(.6)
debounce = false
end
end
end
end)
plr.Character.LeftHand.Touched:connect(function(hit)
if hit.Parent ~= plr.Character then
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
local dividedby = ( plr.leaderstats.Strength.Value / 5 ) + 5
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - dividedby
wait(.6)
debounce = false
end
end
end
end)
end)
wait(2) --cooldown
punchdb[tostring(player.UserId)] = nil
else
player:kick("CL Studios | You were kicked due to unusual client behaviour. Please contact an Admin if you think this is a error.")
end
end)
--LocalScript
local USI = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local DB = false
local Touched = false
USI.InputBegan:Connect(function(key,chat)
if chat then return end
if key.KeyCode == Enum.KeyCode.F then
if DB == false then
DB = true
Touched = true
local random = math.random(1,2)
if random == 1 then
player.Character.Humanoid:LoadAnimation(script.LeftPunch):Play()
game.ReplicatedStorage:FindFirstChild("LePunchLeKid"):FireServer(Touched)
end
if random == 2 then
player.Character.Humanoid:LoadAnimation(script.RightPunch):Play()
game.ReplicatedStorage:WaitForChild("LePunchLeKid"):FireServer(Touched)
end
wait(3.5)
DB = false
Touched = false
end
end
end)
There aren’t any errors, and the localscript is located in starterpack, and there are two animations inside of the localscript.
Thanks for the help in advanced!