#GetPropertyChangedSignal causing weird duplication?

1 messages · Page 1 of 1 (latest)

eternal wagon
#

Hello! I am making a client sided hitbox and everything is working fine except for this one odd thing I can't quite figure out. I have a marker in my animation set to spawn the hitbox which should just run that block but for some reason the debris service runs but then the part gets duplicated on top of itself when fired again? Deleting the GetPropertyChangedSignal function and replacing it with a wait statements works just fine but there has to be a better way to fix it rather than just doing that.

#

It wont let me send the lua script for some reason... so here.

#

There we go

#
UIS.InputBegan:Connect(function(input, gameProcessed)
    
    if gameProcessed then
        return
    end
    
    if input.KeyCode == Enum.KeyCode.Q then
            
        gravity:Play()
        
        gravity:GetMarkerReachedSignal("GravEffect"):Connect(function()
            
            local hrp = pChar:FindFirstChild("HumanoidRootPart")
            
            local hitbox = Instance.new("Part")
            local pos = hrp.Position
            local hitCharacters = {}
            local parameters = OverlapParams.new()
            hitbox.Shape = Enum.PartType.Ball
            hitbox.Size = Vector3.new(10, 10, 10)
            hitbox.CanCollide = false
            hitbox.CanTouch = false
            hitbox.CanQuery = false
            hitbox.Anchored = true
            hitbox.Transparency = 0.5
            
            local cf = hrp.CFrame
            local size = hitbox.Size

            parameters.FilterDescendantsInstances = {pChar}

            local hitboxPart = workspace:GetPartBoundsInBox(cf, size, parameters)
        
            local vTable = {}

            for _, hitPart in pairs(hitboxPart) do
                local vHum = hitPart.Parent:FindFirstChild("Humanoid")
                if vHum and not table.find(vTable, hitPart.Parent) then
                    table.insert(vTable, hitPart.Parent)
                end
            end
            
            hitbox.Position = pos
            hitbox.Parent = workspace
            
            abilityRemote:FireServer(vTable, 3, 6, 75) --I would add a cooldown, magnitude and angle value in here
            game.Debris:AddItem(hitbox, 0.1)

        end)    
    end
end)
round knot
#

nvm is that was debris does

#

ive never used debris service

#

i think its cause you connect the function each time you press Q

#

you should either only connect the function once or disconnect before connecting it again

round knot
# eternal wagon ```lua UIS.InputBegan:Connect(function(input, gameProcessed) if gamePro...

try this

-- Move your GravEffect function outside the UserInput function
-- Only needs to be connected once, otherwise it will stack!
gravity:GetMarkerReachedSignal("GravEffect"):Connect(function()
    
    local hrp = pChar:FindFirstChild("HumanoidRootPart")
    
    local hitbox = Instance.new("Part")
    local pos = hrp.Position
    local hitCharacters = {}
    local parameters = OverlapParams.new()
    hitbox.Shape = Enum.PartType.Ball
    hitbox.Size = Vector3.new(10, 10, 10)
    hitbox.CanCollide = false
    hitbox.CanTouch = false
    hitbox.CanQuery = false
    hitbox.Anchored = true
    hitbox.Transparency = 0.5
    
    local cf = hrp.CFrame
    local size = hitbox.Size

    parameters.FilterDescendantsInstances = {pChar}

    local hitboxPart = workspace:GetPartBoundsInBox(cf, size, parameters)

    local vTable = {}

    for _, hitPart in pairs(hitboxPart) do
        local vHum = hitPart.Parent:FindFirstChild("Humanoid")
        if vHum and not table.find(vTable, hitPart.Parent) then
            table.insert(vTable, hitPart.Parent)
        end
    end
    
    hitbox.Position = pos
    hitbox.Parent = workspace
    
    abilityRemote:FireServer(vTable, 3, 6, 75) --I would add a cooldown, magnitude and angle value in here
    game.Debris:AddItem(hitbox, 0.1)

end)

UIS.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then
        return
    end
    if input.KeyCode == Enum.KeyCode.Q then
        gravity:Play()
    end
end)
#

@eternal wagon let me know if this fixes it or if you still need help

eternal wagon
round knot
#

I'm glad it works! What I think was the problem is that you were using gravity:GetMarkerReachedSignal("GravEffect"):Connect(...) each time you press Q, when you actually only needed to connect the function once Each time you connect a function to the "GravEffect" marker, once the animation reaches that point where it hits the marker, any connected functions will be executed.

That means the first time you pressed Q it would connect your function to the "GravEffect" marker and play the animation properly
The second time you pressed Q it would connect your function a second time to the "GravEffect" marker and play the animation
the problem is that the second time you now have two duplicate functions connected, so once the animation reaches your GravEffect marker it would run both duplicate functions at the same time.
And each time following it would just stack more duplicate functions to the connection each time you press Q