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

How to make a Debounce for every player?

Asked by 3 years ago

I made an ability, it one shots people if I dont use a debounce but if I do it only affects 1 person. I tried make a debounce table but I dont really know how to use tables or dictionaries. the first one I made when the player touched the ability it would add them to the table, second one uses playeradded. basically I dont know how to use tables and dictionaries or how to iterate through them.

local remote = game.ReplicatedStorage.GroundSmash
local DB = false
local spawned = false
local dmglimit = false

remote.OnServerEvent:Connect(function(plr)

    local PlrDB ={}

    local char = plr.Character
    local Hum = char:WaitForChild("Humanoid")
    local HumRoot = char:WaitForChild("HumanoidRootPart")

    local partloc = game.ServerStorage.Classes.UnArmed.GroundSmash
    local Ground = partloc:Clone()
    Ground.Parent = workspace

    Hum.Touched:Connect(function(Floor)
        if spawned == false then
            for i, v in pairs(Ground:GetTouchingParts()) do
                if v:IsA("BasePart") then
                    if Ground.Parent ~= workspace then return end
                    spawned = true
                    Ground.GroundSmash.BrickColor = v.BrickColor
                    Ground.GroundSmash.Material = v.Material    
                    Ground.Sound:Play()
                    Ground.CFrame = HumRoot.CFrame + Vector3.new(0,-3,0)
                    game.Debris:AddItem(Ground, 1.9)
                    wait(5)
                    spawned = false
                end
            end
        end
    end)    

    Ground.Touched:Connect(function(closeobj)
        if DB == false then
            for i, d in pairs(Ground:GetTouchingParts()) do         
                if not d.Parent:FindFirstChild("Humanoid") then
                    if d:IsA("BasePart") then
                        if Ground.GroundSmash.BrickColor ~= d.BrickColor and Ground.GroundSmash.Material ~= d.Material then
                            DB = true
                            Ground.GroundSmash.BrickColor = d.BrickColor
                            Ground.GroundSmash.Material = d.Material
                            wait(3)
                            DB = false
                        end
                    end
                end
            end
        end
    end)

    local TS = game:GetService("TweenService")

    local info = TweenInfo.new(
        0.6,
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.Out,
        0,
        true,
        0
    )

    local goals = {
        Size = Vector3.new(55.501, 13.087, 55.142);
        Transparency = 0
    }

    local goal = {
        Size = Vector3.new(3, 3, 3)
    }

    local twen = TS:Create(Ground.GroundSmash, info, goals)
    local tween = TS:Create(Ground, info, goal)

    tween:Play()
    twen:Play()


    Ground.GroundSmash.Touched:Connect(function(hit)
        local GetPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)   
            if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then           
            --------------------------Debounce here
            hit.Humanoid:TakeDamage(25)

            end
    end)

end)

1 answer

Log in to vote
0
Answered by 3 years ago

im guessing PlrDB is the debounce table

local remote = game.ReplicatedStorage.GroundSmash
local DB = false
local spawned = false
local dmglimit = false

remote.OnServerEvent:Connect(function(plr)

    local PlrDB ={}

    local char = plr.Character
    local Hum = char:WaitForChild("Humanoid")
    local HumRoot = char:WaitForChild("HumanoidRootPart")

    local partloc = game.ServerStorage.Classes.UnArmed.GroundSmash
    local Ground = partloc:Clone()
    Ground.Parent = workspace

    Hum.Touched:Connect(function(Floor)
        if spawned == false then
            for i, v in pairs(Ground:GetTouchingParts()) do
                if v:IsA("BasePart") then
                    if Ground.Parent ~= workspace then return end
                    spawned = true
                    Ground.GroundSmash.BrickColor = v.BrickColor
                    Ground.GroundSmash.Material = v.Material    
                    Ground.Sound:Play()
                    Ground.CFrame = HumRoot.CFrame + Vector3.new(0,-3,0)
                    game.Debris:AddItem(Ground, 1.9)
                    wait(5)
                    spawned = false
                end
            end
        end
    end)    

    Ground.Touched:Connect(function(closeobj)
        if DB == false then
            for i, d in pairs(Ground:GetTouchingParts()) do         
                if not d.Parent:FindFirstChild("Humanoid") then
                    if d:IsA("BasePart") then
                        if Ground.GroundSmash.BrickColor ~= d.BrickColor and Ground.GroundSmash.Material ~= d.Material then
                            DB = true
                            Ground.GroundSmash.BrickColor = d.BrickColor
                            Ground.GroundSmash.Material = d.Material
                            wait(3)
                            DB = false
                        end
                    end
                end
            end
        end
    end)

    local TS = game:GetService("TweenService")

    local info = TweenInfo.new(
        0.6,
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.Out,
        0,
        true,
        0
    )

    local goals = {
        Size = Vector3.new(55.501, 13.087, 55.142);
        Transparency = 0
    }

    local goal = {
        Size = Vector3.new(3, 3, 3)
    }

    local twen = TS:Create(Ground.GroundSmash, info, goals)
    local tween = TS:Create(Ground, info, goal)

    tween:Play()
    twen:Play()

    Ground.GroundSmash.Touched:Connect(function(hit)
        local GetPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)   
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then           
            local hasBeenHit = false

            for i,v in pairs(PlrDB) do -- go through all the players that have been hit, where 'v' is a member in the table/array/dictionary and 'i' is their number in the table. hopefully you already knew this
                if v == hit.Parent then -- check if a player that has been hit is the player the part has touched
                    hasBeenHit = true -- disable
                end
            end

            if hasBeenHit == false then
                hit.Humanoid:TakeDamage(25)
                table.insert(PlrDB,hit.Parent) -- insert to table so it can't be hit again
            end
        end
    end)
end)

0
Wow it was this simple? Ty very much. monsterdanger16 13 — 3y
0
/shrug FurryPapal 90 — 3y
Ad

Answer this question