‘for some reason the player isn’t being damaged. If anyone has a fix, plz help!’
I need help with my script for a part that damages the player over time dependent on their current speed.
→ Here’s the script I cooked up
local damagePart = script.Parent
local baseDamage = 10
local speedMultiplier = 0.5
local playersTouching = {}
local function calculateDamage(humanoid)
local currentSpeed = humanoid.WalkSpeed
local extraDamage = (currentSpeed - humanoid.WalkSpeed) * speedMultiplier
return baseDamage + extraDamage
end
local function damageOverTime(humanoid)
while playersTouching[humanoid] do
local damage = calculateDamage(humanoid)
humanoid:TakeDamage(damage)
wait(1)
end
end
local function onTouch(hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
local humanoid = character.Humanoid
if not playersTouching[humanoid] then
playersTouching[humanoid] = true
damageOverTime(humanoid)
end
end
end
local function onTouchEnd(hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
local humanoid = character.Humanoid
playersTouching[humanoid] = nil
end
end
damagePart.CanCollide = false
damagePart.Touched:Connect(onTouch)
damagePart.TouchEnded:Connect(onTouchEnd)
The problem is that the part is ‘CanCollide = false’ so for some reason the player isn’t being damaged. If anyone has a fix, plz help!