Damage OverTime not working

Sure thing. I’ll transform the function to be more customizable below after the edit is made.

“time” I think you got the variable wrong?

time is a built-in function, you can’t use that as a local variable name.

2 Likes

so i need to do Time?
(30303030)

Judging from your code, yes. You should keep in mind that variable names in coding are case sensitive.

hmm, it did not work… i dont know why?.. this time no errors or anything

also here is the original post i used:

but i do not know what _G is so i tried making it a normal function…

local damagePerSecond = 15
function damageovertimefunc(Humanoid, Dmg, Time, STEP)
	local tPass = 1
    while(Humanoid.Health > 0 and tPass <= Time)do
		Humanoid:TakeDamage(Dmg)
		tPass = tPass + 1
        wait(STEP)
    end
end
-- Function damages Humanoid with Dmg per STEP seconds until Time seconds have passed (or Humanoid's health is at 0)
game.Players.PlayerAdded:Connect(function (player)
    player.CharacterAdded:Connect(function (character)
        damageovertimefunc(character.Humanoid, 4, 4, 0.5
    end)
end)

Here you go. Happy programming!

1 Like

well once again it should call the damage over time when a remote event gets a .OnServerEvent… thank you for your contributing though; i don’t need you to do everything for me ik how to program but idk what the issue with my code was…

You can just use the function I gave and plug that into your specific connections that you wanted. Best of luck!

1 Like

Hince an example.

30charssssss

Sorry, what? And is that a signature?

1 Like

when i did that the damage just went on forever :frowning:

code:

local rp = game.ReplicatedStorage
local remotes = rp.Remotes
local virusremote = remotes.Virus

local damagePerSecond = 4
function damageovertimefunc(Humanoid, Dmg, Time, STEP)
	local tPass = 1
    while(Humanoid.Health > 0 and tPass <= Time)do
		Humanoid:TakeDamage(Dmg)
		tPass = tPass + 1
        wait(STEP)
    end
end

virusremote.OnServerEvent:Connect(function(Player)
	print(Player)
	local Character = Player.Character
	print(Character)
	local humanoid = Character:WaitForChild("Humanoid")
	local length = 4;
	local damagepertimestep = 4;
	local timestep = 0.5;
	--[[local function doDamageThings()
		print("gg gamer")
   		for _ = 1, length, timestep do
        	humanoid:TakeDamage(damagepertimestep);
       		wait(timestep);
		end
	end]]--
	damageovertimefunc(humanoid,4,4,0.5)
	--Character.Infected = false
end)

– Gave code identical to above post on accident. –

that code is the exact same…

My apologies. I thought you still had your own code.

It appears I made my code assume that you always input STEP as 1. Try this instead:

local rp = game.ReplicatedStorage
local remotes = rp.Remotes
local virusremote = remotes.Virus

local damagePerSecond = 4
function damageovertimefunc(Humanoid, Dmg, Time, STEP)
	local tPass = 1
    while(Humanoid.Health > 0 and tPass <= Time)do
		Humanoid:TakeDamage(Dmg)
		tPass = tPass + STEP
        wait(STEP)
    end
end

virusremote.OnServerEvent:Connect(function(Player)
	print(Player)
	local Character = Player.Character
	print(Character)
	local humanoid = Character:WaitForChild("Humanoid")
	local length = 4;
	local damagepertimestep = 4;
	local timestep = 0.5;
	--[[local function doDamageThings()
		print("gg gamer")
   		for _ = 1, length, timestep do
        	humanoid:TakeDamage(damagepertimestep);
       		wait(timestep);
		end
	end]]--
	damageovertimefunc(humanoid,4,4,0.5)
	--Character.Infected = false
end)

so i’m starting to think the code works; but theres an issue
a script in starterpack checks every 3 seconds if the person is infected, if they are it will fire the damage over time.
there is a boolvalue inside of the character named “Infected”
i get this error
attempt to concatenate string with instance
Screen Shot 2020-07-12 at 10.16.19 PM

codes:

local rp = game.ReplicatedStorage
local remotes = rp.Remotes
local virusremote = remotes.Virus

local damagePerSecond = 4
function damageovertimefunc(Humanoid, Dmg, Time, STEP)
	local tPass = 1
    while(Humanoid.Health > 0 and tPass <= Time)do
		Humanoid:TakeDamage(Dmg)
		tPass = tPass + STEP
        wait(STEP)
    end
end

virusremote.OnServerEvent:Connect(function(Player)
	print(Player)
	local Character = Player.Character
	print(Character)
	local humanoid = Character:WaitForChild("Humanoid")
	local length = 4;
	local damagepertimestep = 4;
	local timestep = 0.5;
	--[[local function doDamageThings()
		print("gg gamer")
   		for _ = 1, length, timestep do
        	humanoid:TakeDamage(damagepertimestep);
       		wait(timestep);
		end
	end]]--
	damageovertimefunc(humanoid,4,4,0.5)
	print(Character.."Is getting damaged")
	local infectedbool = Character:WaitForChild("Infected")
	infectedbool.Value = false
end)
local rp = game.ReplicatedStorage
local remotes = rp.Remotes
local virusremote = remotes.Virus

--[[virusremote.OnClientEvent:Connect(function(enemyplr,enemychar)
	--print(enemyplr.."'s Character is "..enemychar)
	print("ok")
	
end)]]--


local Player = game.Players.LocalPlayer

repeat wait() until Player

local Character = Player.Character

repeat wait() until Character

local VirusBool = Character:WaitForChild("Infected")

while wait(3) do
	print("ok you aren't")
	if VirusBool.Value == true then
		local cc = game:GetService("Lighting").Virus
		cc.Enabled = true
		print("bro virus is tru")
		virusremote:FireServer(Player,Character)
		--wait(4)
		--cc.Enabled = false
		--VirusBool.Value = false
	end
end

virusremote.OnClientEvent:Connect(function(Player)
	print("recieved event")
	local newchar = Player.Character
	newchar.Infected = false
end)

also the virus remote does not recieve the onclientevent

while wait(3) do is most likely the problem.
Maybe you meant repeat wait(3) until? wait(3) is a function and while()do is like a IF function, where inside the () is a statement like true

And unlike the IF function, the WHILE will repeat the IF statement until the statement is false. Think of it as while (statement) is true, do (code)

so i should have

while VirusBool.Value == true do
    virusremote:FireServer(Player,Character)
end

? or should i have

repeat wait(3) until VirusBool.Value == true do

end

This piece of code seems like your best bet.