Need help with a infect script

I am trying to create a script that infects other players when the zombified player touches the other players, and for some reason it puts so many scripts into the character that the server crashes. I tried using debounce but that didn’t work for some reason.

That’s my script which is in the character of the zombie player (It’s a normal script)

local torso = script.Parent:WaitForChild("UpperTorso")
local Players = game:GetService("Players")

local debounce = false
torso.Touched:Connect(function(hit)
	local player = hit.Parent
	local Player = Players:GetPlayerFromCharacter(player)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Infected") and debounce == false then
		debounce = true

		if not hit.Parent:FindFirstChild("PlayerAnomaly") then
			local AnomalyPlayer = Instance.new("BoolValue")
			AnomalyPlayer.Parent = player
			AnomalyPlayer.Name = "PlayerAnomaly"
		end

		player.Humanoid:UnequipTools()
		if Player then
			for i, Tool in pairs(Player.Backpack:GetChildren()) do
				Tool:Destroy()
			end
		end

		for i, Part in pairs(player:GetChildren()) do
			if Part:IsA("BasePart") then
				Part.BrickColor = BrickColor.new("Grime")
			end
		end
		
		local Infect = game.ServerStorage.Infect:Clone()
		Infect.Parent = player
		Infect.Enabled = true
		
		game.ServerStorage.Groan:Clone().Parent = player.Head
	end
	wait(0.1)
	debounce = false
end)
1 Like

try increasing the wait(), it’s wayy to short

1 Like

I increased it to 1 second but still makes the server crash

1 Like

I think what’s happening here is that you don’t add the BoolValue “Infected” to the character that you’ve infected. If the character will then be given a script to infect others, it will continuously infect itself until it has so many scripts the server just crashes.

So add this piece of code after “debounce = true”

local infected=Instance.new("BoolValue",hit.Parent)
infected.Name="Infected"
infected.Value=true
2 Likes

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