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

(SOLVED)Using a table to keep track of what a part has collided with? (Explosion.Hit)

Asked by
soutpansa 120
5 years ago
Edited 5 years ago

Solved this by creating a table for each player, before it does damage I do HitDetection[Player] = {}

I'm using explosions for hit detection, but it does damage for each body part the player has, which obviously makes it do way too much damage. Instead of creating an ugly system that detects when a "hit" value has been changed, or lock the part to only hitting 1 player at a time, I'd like to try and do it with tables.

script i use for damage, parts where im having issues have been commented on

local HitTable = {}
local a = HitDetectionModule.new(Waterbomb, Player, true) --true = debounce
        local b = a:SetUp(1, false) -- 1 = number of repeats
        Waterbomb.Size = Vector3.new(SizeCharge[Player])
        Waterbomb.Parent = Player.Character.Bin
        b.Event:Connect(function(Hit)
            local Explosion = Instance.new("Explosion")
            Explosion.Position = Waterbomb.Position
            CurrentSkill[Player] = "Waterbomb Explode"
            Storage.Remotes.General.Effect:FireAllClients(Player,CurrentSkill[Player],Waterbomb.CFrame, SizeCharge[Player])
            Waterbomb:Destroy()
            Explosion.Visible = false
            Explosion.BlastPressure = 0
            Explosion.BlastRadius = SizeCharge[Player] + 2
            if Explosion.BlastRadius < 10 then Explosion.BlastRadius = 10 end
            Explosion.DestroyJointRadiusPercent = 0
            Explosion.ExplosionType = Enum.ExplosionType.NoCraters
            Explosion.Parent = workspace
            local PlayerHitTable = HitTable[Player]
            Explosion.Hit:Connect(function(Part)
                if Part.Parent ~= Player.Character and Part.Parent:FindFirstChild("Humanoid") and not Part.Parent:FindFirstChild("ForceField") then
                    --table.insert(HitTable[Player], Part.Parent) -- this gives an error (table expected, got nil)
                    table.insert(HitTable, Part.Parent) -- this works, but I need it to keep track for each player
                    local Damage = Player.Stats.Level.Value * 1.8 + Power[Player] 
                    Part.Parent.Humanoid:TakeDamage(Damage)
                    local BVV = Instance.new("BodyVelocity")
                    BVV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
                    BVV.Velocity = Vector3.new(math.random(5,10),SizeCharge[Player]+ 20,math.random(5,10))
                    BVV.Parent = Part.Parent:FindFirstChild("HumanoidRootPart")
                    delay(.8, function() BVV:Destroy() end)
                    print(Damage)
                end
            end)
        end)

thanks for reading!

Answer this question