Heya! Recently I’ve been trying to make a disease script. Most of it works except one detail, getting the disease when touching an infected individual.
-
What do you want to achieve? Keep it simple and clear!
I want it so when a player touches and infected player, they will also be infected.
Additionally, my Universal Cure tool cures everyone instead of the person who has the tool, I’m more concerned on the infection rather than the cure right now though.
-
What is the issue? Include screenshots / videos if possible!
It doesn’t make the other player sick when touched. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried using a remote event and bindable event but neither worked. Searching up infection on google or anywhere just gets those model viruses.
There’s a lot of code, I’ll compress the ones that I believe aren’t related to the issue.
Local Script - StarterPlayerScripts
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CollectionService = game:GetService("CollectionService")
local virusremote = game.ReplicatedStorage.VirusRemote
wait(10)
ColdTurnOff = false
FluTurnOff = false
TuberTurnOff = false
game.ReplicatedStorage.VirusCold.OnClientEvent:Connect(function(disease)
if disease == "Cold" then
ColdTurnOff = true
elseif disease == "Flu" then
FluTurnOff = true
elseif disease == "Tuber" then
TuberTurnOff = true
end
end)
while true do
local newRandom
local oldRandom = newRandom
local chosenDisease
local oldchosenDisease= chosenDisease
if TuberOn == true then
for count = 1, 60 do
wait(1)
if TuberTurnOff == true then
TuberTurnOff = false
break
end
end
TuberOn = false
elseif FluOn == true then
for count = 1, 300 do
wait(1)
if FluTurnOff == true then
FluTurnOff = false
break
end
end
FluOn = false
elseif ColdOn == true then
for count = 1, 30 do
wait(16)
if ColdTurnOff == true then
ColdTurnOff = false
break
end
end
ColdOn = false
end
do repeat
newRandom = math.random(20, 30)
wait()
until
newRandom ~= oldRandom
end
do repeat
chosenDisease = math.random(0, 100)
wait()
until
chosenDisease ~= oldchosenDisease
end
wait(newRandom)
print(chosenDisease)
TuberOn = false
FluOn = false
ColdOn = false
if chosenDisease >= 90 then
print("Tuberculosis!")
virusremote:FireServer("Tuber", Player.Character)
TuberOn = true
elseif chosenDisease >= 85 then
print("Flu!")
virusremote:FireServer("Flu", Player.Character)
FluOn = true
elseif chosenDisease >= 65 then
print("Cold!")
virusremote:FireServer("Cold", Player.Character)
ColdOn = true
elseif chosenDisease >= 0 then
print("None!")
end
end
StarterPack Tools (Multiple tools)
Local Script - Cure
local tool = script.Parent
local player = game.Players.LocalPlayer
local Debounce = true
local virusremote = game.ReplicatedStorage.VirusRemote
local player = game.Players.LocalPlayer
tool.Activated:Connect(function()
Debounce = false
virusremote:FireServer("remove disease", player.Character)
wait(1)
Debounce = true
end)
Local Script - ColdInfective
local tool = script.Parent
local player = game.Players.LocalPlayer
local Debounce = true
local virusremote = game.ReplicatedStorage.VirusRemote
local player = game.Players.LocalPlayer
tool.Activated:Connect(function()
Debounce = false
virusremote:FireServer("Cold", player.Character)
wait(1)
Debounce = true
end)
Local Script - FluInfective
local tool = script.Parent
local player = game.Players.LocalPlayer
local Debounce = true
local virusremote = game.ReplicatedStorage.VirusRemote
local player = game.Players.LocalPlayer
tool.Activated:Connect(function()
Debounce = false
virusremote:FireServer("Flu", player.Character)
wait(1)
Debounce = true
end)
Local Script - TuberInfective
local tool = script.Parent
local player = game.Players.LocalPlayer
local Debounce = true
local virusremote = game.ReplicatedStorage.VirusRemote
local player = game.Players.LocalPlayer
tool.Activated:Connect(function()
Debounce = false
virusremote:FireServer("Tuber", player.Character)
wait(1)
Debounce = true
end)
Server Script - ServerScriptService
local virusremote = game.ReplicatedStorage.VirusRemote
local virusbindable = game.ReplicatedStorage.VirusBindable
local coldOn = game.ReplicatedStorage.VirusCold
local contagion = game.ReplicatedStorage.Contagion
local collectionservice = game:GetService("CollectionService")
virusremote.OnServerEvent:Connect(function(originalplr,disease,infectedplr)
virusbindable:Fire(disease,infectedplr)
collectionservice:AddTag(infectedplr,disease)
if originalplr == infectedplr then
if disease == "remove disease" then
coldOn:FireClient(disease)
end
end
end)
contagion.Event:Connect(function(originalplr,disease,infectedplr, hit)
virusbindable:Fire(disease,hit)
collectionservice:AddTag(hit,disease)
if originalplr == hit then
if disease == "remove disease" then
coldOn:FireClient(disease)
end
end
end)
Server Script - ServerScriptService
local collectionservice = game:GetService("CollectionService")
local virusbindable = game.ReplicatedStorage.VirusBindable
local cloning = script:Clone()
local virusremote = game.ReplicatedStorage.VirusRemote
local contagion = game.ReplicatedStorage.Contagion
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
virusbindable.Event:Connect(function(disease,plr)
if disease == "Cold" then
if disease == "Cold" then
for i, v in pairs (character:GetChildren()) do
if v:IsA('BasePart') then
v.Touched:Connect(function(hit)
contagion:Fire("Cold", hit.Parent)
end)
end
end
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
elseif disease == "Flu" then
if disease == "Flu" then
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
elseif disease == "Tuber" then
if disease == "Tuber" then
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
elseif disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
end)
virusbindable.Event:Connect(function(disease,plr)
if disease == "Cold" then
if disease == "Cold" then
local Cough1Copy = game.ServerStorage.Cough1:Clone()
Cough1Copy.Parent = plr.Head
local Cough2Copy = game.ServerStorage.Cough2:Clone()
Cough2Copy.Parent = plr.Head
for count = 1, 30 do
wait(8)
Cough2Copy:Stop()
Cough1Copy:Play()
plr.Humanoid.WalkSpeed = plr.Humanoid.WalkSpeed - .4
wait(8)
Cough1Copy:Stop()
Cough2Copy:Play()
end
Cough1Copy:Destroy()
Cough2Copy:Destroy()
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
elseif disease == "Flu" then
if disease == "Flu" then
for count = 1,300 do
wait(1)
plr.Humanoid.Health = plr.Humanoid.Health - .1
wait()
plr.Humanoid.WalkSpeed = plr.Humanoid.WalkSpeed - .005
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
end
elseif disease == "Tuber" then
if disease == "Tuber" then
for count = 1,60 do
wait(1)
plr.Humanoid.WalkSpeed = plr.Humanoid.WalkSpeed - .1
wait()
plr.Humanoid.Health = plr.Humanoid.Health - 1
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
end
elseif disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
cloning.Parent = script.Parent
plr.Humanoid.WalkSpeed = 16
script:Destroy()
end
end)
end)
end)