Knife infection tool not working error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? So I want this script when it the tool hits a player they get infected

  2. What is the issue? So when I try to hit a player with the tool it gives me this error but I am confused as I see nothing wrong.

  3. What solutions have you tried so far? Nothing.

Here is the script, Thank you very much if you try to help!

-- Tool settings
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(handle.Swing)

-- Infection settings
local infectRadius = 5
local infectDuration = 600 -- 10 minutes
local cooldownDuration = 600 -- 10 minutes

-- Menu settings
local menuTitle = "WARNING!"
local menuDesc = "There is a new infection going around! Please seek immediate shelter and try to not be infected until we find a cure or one of our Bioprepatent joins!"

-- Function to infect a player
local function infectPlayer(player)
	local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- Play infection effect
		local blur = Instance.new("BlurEffect")
		blur.Parent = humanoid.Parent:FindFirstChildOfClass("Camera")
		blur.Size = infectRadius
		blur.Name = "InfectionEffect"

		-- Show infection menu
		local notification = Instance.new("Notification")
		notification.Parent = player.PlayerGui
		notification.Title = menuTitle
		notification.Text = menuDesc

		-- Infect player
		humanoid.WalkSpeed = 0.5 * humanoid.WalkSpeed
		humanoid.JumpPower = 0.5 * humanoid.JumpPower
		humanoid.MaxHealth = 0.5 * humanoid.MaxHealth
		humanoid.Health = humanoid.MaxHealth

		-- Set player as infected
		player:SetAttribute("Infected", true)
		player:SetAttribute("InfectionTime", infectDuration)
	end
end

-- Function to process tool activation
local function onActivated()
	if tool.Enabled then
		-- Play animation
		print("animation played noob")
		animation:Play()

		-- Set tool on cooldown
		tool.Enabled = false
		wait(cooldownDuration)
		tool.Enabled = true
	end
end

-- Connect activation event
tool.Activated:Connect(onActivated)

-- Listen for animation hits
local function onHit(hitPart)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hitPart.Parent)
	if player and not player:GetAttribute("Infected") then
		infectPlayer(player)
	end
end

tool.Handle.Touched:Connect(onHit)

animation:GetMarkerReachedSignal("Infect"):Connect(function()
	local Hit = handle:GetTouchingParts()

	for i,v in pairs(Hit) do 
		if (v.Parent) and (v.Parent:FindFirstChild("Humanoid")) then 
			onHit(v)
		end
	end
end)


-- Listen for infection duration expiration
game:GetService("RunService").Heartbeat:Connect(function(dt)
	for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
		if player:GetAttribute("Infected") then
			local remainingTime = player:GetAttribute("InfectionTime") - dt
			if remainingTime <= 0 then
				-- Cure player
				local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
				if humanoid then
					humanoid.WalkSpeed = 2 * humanoid.WalkSpeed
					humanoid.JumpPower = 2 * humanoid.JumpPower
					humanoid.MaxHealth = 2 * humanoid.MaxHealth
					humanoid.Health = humanoid.MaxHealth
					local blur = humanoid.Parent:FindFirstChildOfClass("BlurEffect")
					if blur then
						blur:Destroy()
					end
				end
				player:SetAttribute("Infected", false)
			else
				player:SetAttribute("InfectionTime", remainingTime)
			end
		end
	end
end)

I hope the following 2 images can speak for themselves.
First read the top message
Unable to create an Instance of type "Notification"

Then while reading your script you create a notification instance?
image

Now let’s look up the notification class:
https://create.roblox.com/docs/reference/engine/classes/Notification
Well this is quite the predicament; Error 404.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.