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

Sword not giving kills, as well of giving phases, also It shows no error In output (?)

Hello!

I'm trying to get a sword that when you get a kill, a kill will be Inserted In the Kills IntValue, however, It does not add a kill, also when you reach a phase, like this example:

5 kills = Phase 1

Its suppose to speed up the player as well of playing a theme, just Its not adding the phase, It also appears to not show a error message In output

Script:

local Tool = script.Parent
local SoundFolder = Tool.Sounds
local SlashAttack
local KillsValue = Tool.Kills
local Boolens = {
	Debounce = false,
	CanDamage = false
}
local Animations = {
	EquipAnimation = Tool.EquipAnimation,
	Idle = Tool.Idle,
	Slash = Tool.Slash,
}

Tool.Equipped:Connect(function()
	SoundFolder.Unsheath:Play()
	local Humanoid = Tool.Parent.Humanoid
	
	local EquipAnimationTrack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.EquipAnimation)
	EquipAnimationTrack:Play()
	task.wait(0.30)
	local Idle = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
	Idle:Play()
	Tool.Unequipped:Connect(function()
		Idle:Stop()
	end)
end)

Tool.Activated:Connect(function()
	if not Boolens.Debounce then
		Boolens.Debounce = true
		Boolens.CanDamage = true
		SoundFolder.Slash:Play()
		print("The tool has been clicked")
		local Humanoid = Tool.Parent.Humanoid

		SlashAttack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Slash)
		SlashAttack:Play()
		task.wait(0.5)
		Boolens.CanDamage = false
		wait(1)
		Boolens.Debounce = false
	end
end)

Tool.Handle.Touched:Connect(function(hit)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if Player then
		local player1 = game.Players:GetPlayerFromCharacter(Tool.Parent)
		local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)

		if (player1 ~= nil) and (player2 ~= nil) then
			local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

			if (player1.TeamColor ~= player2.TeamColor) then
				if (humanoid ~= nil) and Boolens.CanDamage == true then
					Boolens.CanDamage = false
					humanoid:TakeDamage(30)
					if humanoid.Health == 0 then
						SoundFolder["Kill Get"]:Play()
						KillsValue.Value = KillsValue.Value + 1
					end
				end
			end
		end
	else
		local NPCHumanoid = hit.Parent:WaitForChild("Humanoid")
		if NPCHumanoid and Boolens.CanDamage == true then
			Boolens.CanDamage = false
			NPCHumanoid:TakeDamage(30)
			if NPCHumanoid.Health == 0 then
				SoundFolder["Kill Get"]:Play()
				KillsValue.Value = KillsValue.Value + 1
			end
		end
	end
end)

2 answers

✓ Accepted answer

There's a function on Humanoid called Died, It happens when a player or NPC dies

local Tool = script.Parent
local SoundFolder = Tool.Sounds
local SlashAttack
local KillsValue = Tool.Kills
local Boolens = {
	Debounce = false,
	CanDamage = false
}
local Animations = {
	EquipAnimation = Tool.EquipAnimation,
	Idle = Tool.Idle,
	Slash = Tool.Slash,
}

local kills = 0

Tool.Equipped:Connect(function()
	SoundFolder.Unsheath:Play()
	local Humanoid = Tool.Parent.Humanoid

	local EquipAnimationTrack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.EquipAnimation)
	EquipAnimationTrack:Play()
	task.wait(0.30)
	local Idle = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
	Idle:Play()
	Tool.Unequipped:Connect(function()
		Idle:Stop()
	end)
end)

Tool.Activated:Connect(function()
	if not Boolens.Debounce then
		Boolens.Debounce = true
		Boolens.CanDamage = true
		SoundFolder.Slash:Play()
		print("The tool has been clicked")
		local Humanoid = Tool.Parent.Humanoid

		SlashAttack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Slash)
		SlashAttack:Play()
		task.wait(0.5)
		Boolens.CanDamage = false
		wait(1)
		Boolens.Debounce = false
	end
end)

Tool.Handle.Touched:Connect(function(hit)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if Player then
		local player1 = game.Players:GetPlayerFromCharacter(Tool.Parent)
		local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)

		if (player1 ~= nil) and (player2 ~= nil) then
			local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

			if (player1.TeamColor ~= player2.TeamColor) then
				if (humanoid ~= nil) and Boolens.CanDamage == true then
					Boolens.CanDamage = false
					humanoid:TakeDamage(30)
					humanoid.Died:Connect(function()
						SoundFolder["Kill Get"]:Play()
						KillsValue.Value += 1
						kills += 1
						
						if kills >= 5 then

							kills = 0

							player1.Character:FindFirstChild("Humanoid").WalkSpeed = 24

						end
						
					end)
				end
			end
		end
	else
		local NPCHumanoid = hit.Parent:WaitForChild("Humanoid")
		if NPCHumanoid and Boolens.CanDamage == true then
			Boolens.CanDamage = false
			NPCHumanoid:TakeDamage(30)
			NPCHumanoid.Died:Connect(function()
				SoundFolder["Kill Get"]:Play()
				KillsValue.Value += 1
				kills += 1
				
			end)
		end
	end
end)

8 comments

0

Small note: instead of KillsValue.Value = KillsValue.Value + 1 he/she can just do KillsValue += 1

0

Yea

0

Its giving kills, just not adding the phases, also there Is a script Inside a IntValue

0

Wdym not in the phases

0

Basically when you reach lets say 5 kills, you get a speed boost

0

Oh sorry edited

0

Thanks!

0

Np

hey you! have you ever heard of enes? if you are in trouble, better call enes!

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