You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want it when the animation plays and the knife hits a player it will infect them
What is the issue? So when I try to hit someone they dont get infected, There is no single error in the dev console so I am very confused it plays the animation and hits them so yeah
What solutions have you tried so far? Nothing because there is no error.
Please try to look at the script and see what is wrong with it, it is in a local script and outside of the handle in the tool.
-- 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
animation:GetMarkerReachedSignal("Infect")(onHit)
-- 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)
You dont actually check if the tool hit any player.
This script should work:
-- 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
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)
Future reference for urself, syntax, nil, etc, all of those errors that show up in the output arent the only errors. The main errors that we deal with is logic errors which is the hardest one of all. Next time try some solutions, reread ur code or anything :]
He probably doesnt have an animation event so that wouldnt work, but from what i see @MatoWiz you never call the onHit function so the game never knows that you hit someone, unless im blind and do see you calling it ofc.