Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make the ability do dmg per second?

Asked by 5 years ago
Edited 5 years ago

I need to make it to where the ability does 3 dmg per second when a player a touching it

--Server Script--
local tween = game:GetService("TweenService")
local casting = false

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
    if casting == true then return end
    casting = true

    local iceSpikes = game.ReplicatedStorage.LightCage:Clone()
    local dmg = 3
    --Pre position
    iceSpikes:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame)
    iceSpikes.Parent = workspace
    local endPositions = {Position = {}, Orientation = {}}
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        endPositions["Position"][i] = v.Position
        endPositions["Orientation"][i] = v.Orientation
        v.CFrame = CFrame.new(iceSpikes.Center.Position)
    end

    --Activate
    wait(0)
    local Sound = script.Parent.Lightning
    Sound:Play()
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        v.Orientation = endPositions["Orientation"][i]
        tween:Create(v, TweenInfo.new(0), {Position = endPositions["Position"][i]}):Play()
    end

    --Attack
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        v.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") and not hit:IsDescendantOf(player.Character) then --Check if its a player
                local enemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
                enemyHumanoid:TakeDamage(dmg)
            end
        end)
    end

    --Remove
    wait(5)
    Sound:Stop()
    iceSpikes:Destroy()
    casting = false
    wait(2)
    if iceSpikes.Parent == workspace then
        iceSpikes:Destroy()
    end
end)

1 answer

Log in to vote
1
Answered by 5 years ago

i think you overdid urself, theres a .Touched event. u need a debounce cuz it fires insanely

local debounce=false
script.Parent.Touched:Connect(function(hit)--hit is the obj
if hit.Parent:FindFirstChildOfClass("Humanoid") and debounce==false then
debounce=true
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(3)
wait(2)
debounce=false
end



end)
0
what would I replace that with? Justingamer700 114 — 5y
0
Nvm lol. I didn't see the "script.Parent" Justingamer700 114 — 5y
0
Single player game? Because this sort of solution isn't multi-player compatible, just FYI. What I mean is one player touching the damage spike isn't stopping that player from taking damage for another 2 seconds, it stops that spike from damaging *anyone* over the next 2 seconds. That's not really what was asked for, and if this needs to work for more than one player, I would not consider it a solu EmilyBendsSpace 1025 — 5y
0
My instinct would be to do the damage cap at the receiving end, on a per-player basis. Instead of calling TakeDamage() directly, call up to a function in a server script that handles incoming damage and processes it once per second for each player, taking into account the max dmg allowed from each source. Then that script calls TakeDamage with the capped result. EmilyBendsSpace 1025 — 5y
0
..? its a serverscript EmbeddedHorror 299 — 5y
Ad

Answer this question