You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make a sword -
What is the issue? Include screenshots/videos if possible!
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
- 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)```