Broken kill for coins and kills

I just forgot to add the then keyword… I made the script while I was on mobile, so I didn’t see my error. I also optimized the script a bit. It should work now.

local Debris = game:GetService("Debris")
local Players = game:GetService("Players")

local Damage = 50
local cooldown = false
local duration = nil -- change cooldown time or keep nil to wait()

function tagHumanoid(humanoid, player)
	if humanoid:IsA("Humanoid") then
		if not humanoid:FindFirstChild("creator") then
			local creator = Instance.new("ObjectValue")
			creator.Name = "creator"
			creator.Value = player
			Debris:AddItem(creator, 2)
			creator.Parent = humanoid
		else
			for i, v in pairs(humanoid:GetChildren()) do
				if v:IsA("ObjectValue") and v.Name == "creator" then
					v:Destroy()
				end
			end
		end
	end
end

function onTouch(hit)
	if cooldown == true then return end
	cooldown = true
	local Tool = script.Parent.Parent
	if Tool then
		local Model = Tool.Parent
		local Player = Players:GetPlayerFromCharacter(Model)
		if Player then
			local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
			if Humanoid and Humanoid.Parent ~= Model then
				tagHumanoid(Humanoid, Player)
				Humanoid:TakeDamage(Damage)
				if duration == nil then
					wait()
					cooldown = false
					return
				end
				wait(duration)
				cooldown = false
				return
			end
		end
	end
	cooldown = false
end

script.Parent.Touched:Connect(onTouch)

Also, change your leaderstats script to this below because I made a capitalization mistake on “creator”…

Leaderstats
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"

	local Coins = Instance.new("NumberValue")
	Coins.Name = "Coins"
	Coins.Value = 0
	Coins.Parent = leaderstats

	local Kills = Instance.new("NumberValue")
	Kills.Name = "Kills"
	Kills.Value = 0
	Kills.Parent = leaderstats

	leaderstats.Parent = Player

	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		if Humanoid then
			Humanoid.Died:Connect(function()
				local creator = Humanoid:WaitForChild("creator")
				if creator then
					local leaderstats = creator.Value:FindFirstChild("leaderstats")
					if leaderstats then
						leaderstats.Coins.Value += 15
						leaderstats.Kills.Value += 1
					end
				end
			end)
		end
	end)
end)