Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the Touched function play only once with this weapon script?

Everything works fine except the Touched function (Line 46) only plays once and never plays again until you re-equip it. How can I fix it to make it play endlessly?

local tool = script.Parent
local handle = tool.Handle
local equip = handle.Equip
local swing = handle.Swing
local quoteA = handle.QuoteA
local quoteB = handle.QuoteB
local hit = handle.Hit
local anim = tool.BatonSwing
local tik = handle.Tick
local damage = tool.HitBox
local debounce = false

tool.Equipped:Connect(function(Mouse)
	local character = tool.Parent
	local humanoid = character:FindFirstChild("Humanoid")
	local arm = character:FindFirstChild("Right Arm")
	local torso = character:FindFirstChild("Torso")
	local weld = Instance.new("Weld")
	local tik = handle.Tick
	local deboonce = false
	
	equip:Play()
	wait(0.3)
	quoteB:Play()
	
	weld.Parent = torso
	weld.Part0 = torso
	weld.Part1 = arm
	weld.C0 = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(1.5,0,0)
	
	Mouse.Button1Down:Connect(function()
		if not debounce then
			
			debounce = true
			
			tik.Enabled = not tik.Enabled
			for i = 1,10 do
				weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(0.1,0,0)
				wait()
			end
			swing:Play()
			damage.Touched:Connect(function(hit)
				if not deboonce then
					
					deboonce = true
					-- Problems Here v v v
					local char = hit.Parent
					local noid = char:FindFirstChild("Humanoid")
					local hatnoid = char.Parent:FindFirstChild("Humanoid")
					
					if noid then
						print(noid.Name)
						quoteA:Play()
						handle.Hit:Play()
						noid.WalkSpeed = 6
						noid.Sit = true
						wait(3)
						print("You're Free!")
						noid.WalkSpeed = 16
						noid.Sit = false
					else
						print(hatnoid.Name)
						quoteA:Play()
						handle.Hit:Play()
						noid.WalkSpeed = 6
						hatnoid.Sit = true
						wait(3)
						print("You're Free!")
						noid.WalkSpeed = 16
						hatnoid.Sit = false
					end
					wait(0.1)
					-------------
					debounce = false
					
				end
			end)
			for i = 1,5 do
				weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(-0.5,0,0) * CFrame.new(0,0.03,0.2)
				wait()
			end
			wait(0.2)
			weld.C0 = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(1.5,0,0)
			
			debounce = false
			
		end
	end)
	Mouse.Button1Up:Connect(function()
		
	end)
end)
tool.Unequipped:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	local torso = character:FindFirstChild("Torso")
	local armweld = torso:FindFirstChild("Weld")
	
	if armweld then
		armweld:Destroy()
	else
		print("Weld was removed by other causes.")
	end
end)

4 comments

0

You put your touched event inside of a Button1Down event, which can’t run unless the button is down.

0

How do i fix this?

0

It's inside the 'if's ?

0

Hold left click down and let someone run the touched event

1 answer

✓ Accepted answer

###We talked about this on discord, not much explaining needed. heh

tool.Equipped:Connect(function(mouse)
    -- code 
    mouse.Button1Down:Connect(function()
        -- code
    end) 
end)

damage.Touched:Connect(function(hit)
-- code
end)


tool.Unequipped:Connect(function()
    -- code
end)

###Just separare each event into their own code block. The Button1Down needs to be in the Equipped event because it passes the PlayerMouse as a parameter.

This discussion is preserved as it was. New answers, comments, and votes are closed.