Tutorail Sword help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a sword

  2. What is the issue? Include screenshots/videos if possible!
    image

my code: when clicked. For 0.5 sec set debounce to true
if it touched anything and debounce set to true → take damage
**The issue : **touch function only runs 1 time, sword touch-> check is debounce = true ? the player haven’t clicked yet so not true → the player clicked after they checked → the script has problem cuz touch function only execute once

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’m surprised no one has the same problem ;-; (or maybe I just haven’t find it)

I am following this tutorial: How to make a Sword in Roblox Studio - YouTube

local tool = script.Parent.Parent
local sword = tool:FindFirstChild("SwordMesh")
local hitbox = tool.hitbox

local playerHit = {}

local humanoid = game:GetService("Players").LocalPlayer:FindFirstChild("Humanoid")

--sword stats--
local COOLDOWN = 1
local DAMAGE = 50

--local slashAnim = humanoid:LoadAnimation(slash)

debounce = false

tool.Activated:Connect(function()
	if debounce == false then
		print("activated")
		debounce = true
		--slashAnim:Play()
		wait(.5)
		debounce = false
		
	end
end)

hitbox.Touched:Connect(function(part)
	print("touched")
	if part.Parent:FindFirstChild("Humanoid") and part.Parent ~= tool.Parent then
		
		if debounce == true and playerHit[part.Parent] == nil then
			print("part.parent = ", part.Parent)
			
			playerHit[part.Parent] = true
			part.Parent:FindFirstChild("Humanoid"):TakeDamage(DAMAGE)	
		end
	end
end)```

I would assume you should instead use getpartsinpart after the debounce is set to true and then check if the parts in part is a player

WorldRoot | Roblox Creator Documentation

1 Like

oh okay let me search that .never heard of it thx

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.