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

onTouch Function not working the way it has to work?

Summing up:

This onTouch function is doing its job fine:

local function FDamage(Player)
	local GrandSword = Player.Character:FindFirstChild("GrandSword")
    local FValue = Player.Character["GSword Equipper"].FValue
	local Blade = GrandSword.Handle.Union6
	local Connection
	Connection = Blade.Touched:Connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
			if Hit.Parent.Parent ~= Player then
				if not Hit.Parent.Humanoid:FindFirstChild("FValue") then
					local DamageTag = FValue:Clone()
						DamageTag.Parent = Hit.Parent.Humanoid
					Hit.Parent.Humanoid:TakeDamage(10)
			    	game:GetService("Debris"):AddItem(DamageTag,1)
				end
			end		
		end	
	end)
    wait(1)
    Connection:Disconnect()
end

But this one isnt:

local function ZDamage(Player)
	local GrandSword = Player.Character:FindFirstChild("GrandSword")
    local ZValue = Player.Character["GSword Equipper"].ZValue
	local Blade = GrandSword.Handle.Union6
	local Connection
	Connection = Blade.Touched:Connect(function(Hit)
		print(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
			if Hit.Parent.Parent ~= Player then
				if not Hit.Parent.Humanoid:FindFirstChild("ZValue") then
					local DamageTag = ZValue:Clone()
						DamageTag.Parent = Hit.Parent.Humanoid
					Hit.Parent.Humanoid:TakeDamage(20)
			   	    game:GetService("Debris"):AddItem(DamageTag,1)
				end
			end		
		end	
	end)
    wait(1)
    Connection:Disconnect()
end

Any idea of why this one isnt printing the things the part hit?

Btw they are two RemoteEvents activated by an local script that says:

FAttack:FireServer() ZAttack:FireServer()

2 comments

0

And no, line 9 isnt the problem, i tested it already

0

Try to check the output before asking on here. But I'll try to fix it.

1 answer

--> Ok, lets start the coding part

local function zDamage(player)
	local grandSword = player.Character:FindFirstChild("GrandSword")
	local zValue = player.Character[GSword Equipper"].zValue
	local blade = grandSword.Handle.Union6
	local debounce = false

	local function onTouched(hit)
		if not debounce then
			local character = hit parent
			if character then
				local player = game.Players:GetPlayerFromCharacter(character)
				if player then
					local humanoid = character:WaitForChild("Humanoid")
					if not humanoid:FindFirstChild("ZValue") then
						local damageTag = zValue:Clone()
						damageTag.Parent = humanoid
						humanoid:TakeDamage(20)
						local debris = game:GetService("Debris")
						debris:AddItem(damageTag.1)
					end
				end
			end
		end

		-->Lets connnect it to something
		blade.Touched:Connect(onTouched)
	end

	debounce = true
	wait() --> Choose a time you want
	debounce = false
end

--[[	
	Yh, ik what are you thinking. "It's larger!", yh. But it works.
]]

3 comments

0

Its the same thing, plus its giving the same results, it must be some kind of problem with roblox onTouch detection or the animation

0

Nope.

0

It can't be

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