I need help, I have 008 script that makes you infected once you touch part, but I do not know how to make, so when infected player touch other player, they get infected too. Here’s script:
local part = game.Workspace.sussy
local function ColorChanger(BodyColor) --Infected function
BodyColor.HeadColor = BrickColor.new("Lime green")
wait(0.1)
BodyColor.LeftArmColor = BrickColor.new("Lime green")
wait(0.1)
BodyColor.RightArmColor = BrickColor.new("Lime green")
wait(0.1)
BodyColor.LeftLegColor = BrickColor.new("Lime green")
wait(0.1)
BodyColor.RightLegColor = BrickColor.new("Lime green")
wait(0.1)
BodyColor.TorsoColor = BrickColor.new("Lime green")
end
local function GoInfected(player)
player:FindFirstChild("Pants").PantsTemplate = "http://www.roblox.com/asset/?id=0"
player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=0"
if player:FindFirstChild("Shirt Graphic") then
player:FindFirstChild("Shirt Graphic").Graphic = "http://www.roblox.com/asset/?id=0"
end
for _, desc in ipairs(player:GetDescendants()) do
if desc:IsA('Accessory') and desc:FindFirstChild('Handle') and desc.Handle:FindFirstChild('HairAttachment') then desc:Destroy() end
end
end
part.Touched:Connect(function(hit)
local BodyColors = hit.Parent:FindFirstChild("Body Colors")
local Player = hit.Parent
local humanoid = Player:FindFirstChild("Humanoid")
Player.Parent = game.Workspace.infected
wait(5)
ColorChanger(BodyColors)
GoInfected(Player)
wait(5)
for i = 100, 0, -1 do
humanoid.Health = i
wait(5)
end
end)
You can add some error handling to your code to ensure that it runs smoothly. For example, you can check if the Body Colors instance exists before calling the ColorChanger function, and you can check if the player has a Humanoid before reducing their health.
It’s a good practice to use a while loop instead of a for loop to gradually reduce the player’s health. This way, you can stop the loop if the player dies or if they are no longer touching the part.
local Character = script.Parent
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
local CollectionService = game:GetService("CollectionService")
function Infect(Character:Model?)
if not CollectionService:HasTag(Character, "Zombie") then
CollectionService:AddTag(Character, "Zombie")
end
end
local function ColorChanger(Player:Player?) --Infected function
local BC = Player.Character:FindFirstChildOfClass("BodyColors")
for _,v in Enum.BodyPart:GetEnumItems() do
BC[v.Name.."Color"] = BrickColor.new("Lime green")
task.wait(0.1)
end
end
local function GoInfected(player)
player:FindFirstChild("Pants").PantsTemplate = "http://www.roblox.com/asset/?id=0"
player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=0"
if player:FindFirstChild("Shirt Graphic") then
player:FindFirstChild("Shirt Graphic").Graphic = "http://www.roblox.com/asset/?id=0"
end
for _, desc in ipairs(player:GetDescendants()) do
if desc:IsA('Accessory') and desc:FindFirstChild('Handle') and desc.Handle:FindFirstChild('HairAttachment') then desc:Destroy() end
end
end
for _,v in Character:GetChildren() do
if v:IsA("BasePart") then
if v.Name == "Right Arm" or v.Name == "Left Arm" and Character.Parent == game.Workspace.Infected then
v.Touched:Connect(function(Part)
local VictimPLAYER = game:GetService("Players"):GetPlayerFromCharacter(Part)
if VictimPLAYER ~= nil and VictimPLAYER ~= Player and VictimPLAYER.Character and CollectionService:HasTag(VictimPLAYER.Character, "Zombie") and CollectionService:HasTag(Character, "Zombie") or Character.Parent == game.Workspace.Infected then
VictimPLAYER.Character.Parent = game.Workspace.Infected
Infect(VictimPLAYER.Character)
ColorChanger(VictimPLAYER)
GoInfected(VictimPLAYER)
task.wait(5)
task.spawn(function()
for i = 100, 0, -1 do
VictimPLAYER.Character:FindFirstChildOfClass("Humanoid").Health = i
task.wait(1)
end
end)
end
end)
end
end
end
for _,v in Character:GetChildren() do
if v:IsA("BasePart") then
if v.Name == "Right Arm" or v.Name == "Left Arm" then then
v.Touched:Connect(function(Part)
print("Touched")
local VictimPLAYER = game:GetService("Players"):GetPlayerFromCharacter(Part)
if VictimPLAYER ~= nil and VictimPLAYER ~= Player and VictimPLAYER.Character and not CollectionService:HasTag(VictimPLAYER.Character, "Zombie") or VictimPLAYER.Character ~= game.Workspace.Infected and CollectionService:HasTag(Character, "Zombie") or Character.Parent == game.Workspace.Infected then
VictimPLAYER.Character.Parent = game.Workspace.Infected
print("infecting")
Infect(VictimPLAYER.Character)
ColorChanger(VictimPLAYER)
GoInfected(VictimPLAYER)
task.wait(5)
task.spawn(function()
for i = 100, 0, -1 do
VictimPLAYER.Character:FindFirstChildOfClass("Humanoid").Health = i
task.wait(1)
end
end)
else
print("player is already infected")
end
end)
end
end
end
The ColorChanger() and GoInfected() function are not defined in the code you shared, so the script will throw an error when trying to execute those functions. You should either add the functions to the script or make sure they are being imported from elsewhere in your code. Also, I would recommend adding additional checks to make sure BodyColors and humanoid are not null before using them. For example:
part.Touched:Connect(function(hit)
local BodyColors = hit.Parent:FindFirstChild("Body Colors")
local Player = hit.Parent
local humanoid = Player:FindFirstChild("Humanoid")
if BodyColors and humanoid then
Player.Parent = game.Workspace.infected
wait(5)
ColorChanger(BodyColors)
GoInfected(Player)
wait(5)
for i = 100, 0, -1 do
humanoid.Health = i
wait(5)
end
end
end)
This way you prevent code from breaking in case BodyColors or humanoid are null.