Hate being the noob lol, I attempted to create a killpart script from scratch that takes incremental damage over time whilst a player is touching the part, but I’m stuck with the loop. Once I touch the part, it doesn’t matter if I leave the block, it keeps damaging the player.
How far off was I?
--//Variables
local Human = game:GetService("Players")
local Damage = 5
--//Functions
script.Parent.Touched:Connect(function(hit)
Human = hit.Parent:FindFirstChild("Humanoid")
if Human then
while Human do
Human.Parent.Humanoid:TakeDamage(Damage)
wait(1)
if Human == nil then
break
end
end
end
end)
Use a touchEnded event to change a bool value (whether he is touching or not) and have the while loop by itself at the end of the script, you were close to getting it right!
local damage = 5--I'm using camelCaseNotation if the variable isn't an instance.
script.Parent.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if not Humanoid then return end -- Exit the function if there's no Humanoid at all.
while table.find(script.Parent:GetTouchingParts(),Hit) do--Here I check if "Hit" is still a touching part.
Humanoid:TakeDamage(damage)
wait(1)
end
end)