i need suggestions on what to use
the player take for example 10 damage every 5 seconds and it stops after 10 seconds
what functions or events do i use so i could make a part like this?
Please read post rule before making posts like this. These kinds of posts that make no sense and give no description about anything are against the category’s rules. Find it here:
https://devforum.roblox.com/t/about-the-scripting-support-category/45863/2
This is very vague, so I will give you something very vague. Make the character take damage
No like so it takes damage by time.
like when the player touched the part he gets damaged every 5 seconds
im just asking on what to use.
Could you please update your post because no one can make out what you are trying to ask.
i need suggestions on what to use for the part’s script
Dude, like come on. Listen to what they are saying. No one knows what you want them to help you with, please fix your post to make it more understandable.
Script inside character
What you could do is use a while loop
Instead of having it say something like “while true do”, you could have a variable that changes to false when you finish dealing damage to the player.
You could also have variables that change depending on the poison you’re using.
something like
local character = script.Parent -- this is assuming the script is inside the character (a server script)
local damage = 10 -- how much damage to deal
local secondsBetweenDamage = 5 -- the seconds between each damage tick
local totalDamageTime = 10 -- the total amount of time that will pass
local finishedDeal = false -- a variable used to check if the poison finished
local humanoid = character:WaitForChild("Humanoid") --find humanoid in the character
local timePassed = 0 -- how much time has passed
while finishedDeal == false do -- only deal damage if it hasn't finished
wait(secondsBetweenDamage) --wait for time between damage
timePassed = timePassed + secondsBetweenDamage -- add to timePassed
humanoid:TakeDamage(damage) -- damage the humanoid
if timePassed >= totalDamageTime then -- check if timepassed is equal to or greater than the total time to deal damage
finishedDeal = true -- end the loop of dealing damage by setting this to true
end
end
Script inside a part
If you wanted to do it after a player touches a part, you would have a script check when that part was touched with a .Touched event
This checks if another part touches it, which could be a part of a player’s character.
You could also have a function that deals damage to the player if the player isn’t already being dealt damage. You can go about this with another variable that’s a table of players that are already being deal damage
This uses game.Players:GetPlayerFromCharacter()
It also used for i,v in pairs loops
local part = script.Parent -- assuming this script is inside the part
local playersBeingDamaged = {} -- a table that will store who is already being dealt damage
local damage = 10 -- how much damage to deal
local secondsBetweenDamage = 5 -- the seconds between each damage tick
local totalDamageTime = 10 -- the total amount of time that will pass
function dealDamage(player)
table.insert(playersBeingDamaged,player) --insert the player into the table
local finishedDeal = false -- a variable used to check if the poison finished
local humanoid = character:WaitForChild("Humanoid") --find humanoid in the character
local timePassed = 0 -- how much time has passed
local character = player.Character
local humanoid = character.Humanoid
while finishedDeal == false do -- only deal damage if it hasn't finished
wait(secondsBetweenDamage) --wait for time between damage
timePassed = timePassed + secondsBetweenDamage -- add to timePassed
humanoid:TakeDamage(damage) -- damage the humanoid
if timePassed >= totalDamageTime then -- check if timepassed is equal to or greater than the total time to deal damage
finishedDeal = true -- end the loop of dealing damage by setting this to true
end
end
for i,plr in pairs (playersBeingDamaged) do --find the player in the table and remove them from it
if plr == player then
table.remove(playersBeingDamaged,i) -- remove the index of the player
end
end
end
part.Touched:connect(function(hit)
if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then --check if the hit part belongs to a player's character
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local doDamage = true
for i,v in pairs (playersBeingDamaged) do
if v == player then
doDamage = false
break
end
end
if doDamage == true then
dealDamage(player)
end
end
end)
Easiest way to crunch that work down is to determine how many seconds damage will last for and how much damage should be dealt to the player, then divide so you can get the DPS lasting over the time period and accordingly deal damage.
local damage = 50
local timePeriod = 15
local damagePerSecond = timePeriod/damage
Indeed you can do that. I’m trying to simplify the process as much as possible for him, though.
i literally edited it and i think its understandable,
a poison part that poisons players for a duration of time then stops (damages the player for a duration of time).
I will try that.
(Btw at the first script why not use FindFirstChild)
That works but it errored,
The
local character = player.Character
shouldve been above the
local humanoid = character:WaitForChild(“Humanoid”)
so i edited it a little and it worked, Anyways thank you for your help!
Woops! I wrote both scripts in the devforums itself.
I’m glad it works! Good luck with everything.