You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? So I want this script when it the tool hits a player they get infected
-
What is the issue? So when I try to activate this tool I get an error in this screenshot and it doesn"t work
-
What solutions have you tried so far? Nothing, because it seems like the script is fine?
Here is the script! Hope anyone could help me out!
-- 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)