Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make something take damage over time?

How will i be able to make something that if a player like player1 touch player2. player2 will start taking damage over time and add like a button to activate for it to happen. If you can help me figure out what to do with this script i will be really happy :D. Well i already know how to get a button to activate it just only the touching and and damage over time

1 answer

✓ Accepted answer

I have classified a few things in the script that might be helpful to figure out what the script entirely does. I haven't tested this so I don't know if it works or not. Hopefully this is what you were wanting help with and don't hesitate to tell me if it doesn't work or a question about it.


settings = { --This is a table, this table will store all the variables that you can change.
damageTime = 6, -- How many times It will damage the player
inbetweenTime = .5, -- The time you have to wait until It damages again
damage = 10, -- How much damage it will do
debounce = false, -- Not recommended to change this
}
game.Players.PlayerAdded:Connect(function(playerWait)
	playerWait.CharacterAdded:Connect(function(characterWait)
for i,v in pairs(game.Players:GetChildren()) do --[[ Grab all the players in the player service --]]
repeat wait() until workspace:FindFirstChild(v.Name)
workspace[v.Name].Touched:Connect(function(hit) --[[ This is a function which will fire when it is touched --]]
if hit.Parent:FindFirstChildOfClass('Humanoid') then --[[ This will check if it hits something w/ a humanoid --]]
if not settings.debounce then -- Checks if debounce is false
settings.debounce = true
for i = 1,settings.damageTime do -- This is a for loop that will loop a certain amount of times
hit.Parent:FindFirstChildOfClass('Humanoid'):TakeDamage(settings.damage) --[[ this will take damage--]]
wait(settings.inbetweenTime) -- this will wait for the time classified in settings.
end
settings.debounce = false
end
end
end)
end
end)
end)

14 comments

0

k thanks :D

0

for the 8 part i ahve to put a name in the brackets what if I want it to happen to everyone not just a certin player?

0

let me modify the script with that

0

kk thanks

0

okay modified.

0

If i added a wait.. Would it be right after part 14 as the time it will last for and then a wait after 16 for until u may be able to use it again?

0

Ty so much I really never get this much help.

0

All good and yes put a wait after line 16 for the length you want to wait until they can use it again and line 14 is the time it waits until it repeats the for loop, on line 12 is the amount of times it loops, but you can change the loop number in the settings table located at line 01.

0

kk thanks

0

Could you put in the modified script changes into wherever you are storing your script, I made a mistake where there was a missing end and where It wouldn't work because the player hasn't been localised in the Workspace Service.

0

oh kk

0

If i added the press certin key to use like e where would it be and what line will i use?

0

Check your recent question I just answered it.

0

kk ty

This discussion is preserved as it was. New answers, comments, and votes are closed.