How do i make it so that i cant just swing the sword and then walk up to the player to do damage? I have no idea how this is happening pls help.
Local script in startercharacterscripts -
local debounce = true
local function Attack()
local remoteevent = game.ReplicatedStorage.RemoteEvents.Combat.Attack
if debounce == true then
remoteevent:FireServer(equipped, debounce)
debounce = false
end
end
server script in startercharacterscripts -
local RemoteEvent = game.ReplicatedStorage.RemoteEvents.Combat.Attack
local connection -- Declare a variable to store the connection
local connection = RemoteEvent.OnServerEvent:Connect(function(player, equipped, debounce)
local debounce = true
print("passed2")
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local damageValue = 10 -- Set the base damage value
local sword = char:WaitForChild("Sword"):FindFirstChild("Handle")
local function onSwordTouched(part)
if part.Parent and part.Parent:FindFirstChild("Humanoid") and equipped and debounce then
local targetHumanoid = part.Parent.Humanoid
if not part.Parent:FindFirstChild("Blocking").Value and not targetHumanoid:GetAttribute("RecentlyHit") then
-- Player is not blocking, and the target hasn't been recently hit
if debounce == true then
print("yeuh")
debounce = false
targetHumanoid:TakeDamage(damageValue)
targetHumanoid:SetAttribute("RecentlyHit", true)
wait(0.5)
targetHumanoid:SetAttribute("RecentlyHit", false)
elseif debounce == false then
print("No")
end
end
end
end
sword.Touched:Connect(onSwordTouched) -- Connect the event
end)
** You are now Level 1! **