#Why does the hitbox not care about this boolvalue?

1 messages · Page 1 of 1 (latest)

real patrol
#

Im testing out module scripts and i just applied one to hitboxes for an attack. However the hitboxes dont respect the boolvalue and keep killing the player even though they should only take 25 damage.

#

im really confused since it was working early, probably a bug with either wifi or the module

cedar epoch
#

showing it in a video is very inefficient

real patrol
#

oh yeah that makes sense

tepid daggerBOT
#

studio** You are now Level 3! **studio

real patrol
#

ill get it ready

#
local attack = {}

attack.hitboxes = {}

function attack.hitboxmake(cooldown, tool, alreadyhit, size)
    local hitbox = Instance.new("Part")
    hitbox.Anchored = true
    hitbox.CanCollide = false
    hitbox.Size = size
    hitbox.Color = Color3.new(1, 0.168627, 0.168627)
    hitbox.Material = Enum.Material.ForceField
    hitbox.Transparency = 0.3
    hitbox.Parent = game.Workspace
    hitbox.CFrame = tool.Parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, -5.5)
    hitbox.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= tool.Parent.Name and alreadyhit == false then
            print("Hit")
            print(hit.Parent.Name)
            hit.Parent.Humanoid:TakeDamage(25)
            alreadyhit = true
            task.wait(cooldown)
        end
    end)
    game.Debris:AddItem(hitbox, 0.5)
end


return attack
real patrol
# cedar epoch send code in a codeblock
local m1event = game.ReplicatedStorage.Events.Killer["2011X"].m1
local stats = {
    tool = script.Parent,
    cooldown = 2,
    alreadyhit = false,
    size = Vector3.new(5, 6, 5),
    duringattack = false,
    keybind = Enum.UserInputType.MouseButton1,
}

local attack = require(game.ServerStorage.Modules.ModuleScript)

m1event.OnServerEvent:Connect(function()
    print("Event received")
    stats.tool:Activate()
end)

stats.tool.Activated:Connect(function()
    if stats.duringattack == false then
        print("Used Punch")
        stats.duringattack = true
        task.delay(stats.cooldown, function()
            stats.duringattack = false
        end)
        local player = game.Players:GetPlayerFromCharacter(stats.tool.Parent)
        local humanoid = player.Character:WaitForChild("Humanoid")
        local animator = humanoid.Animator
        local hitAnim = Instance.new("Animation")
        hitAnim.AnimationId = "rbxassetid://125113366268147"
        local hitTrack = animator:LoadAnimation(hitAnim)
        if hitTrack then
            hitTrack:Play()
            hitTrack.Looped = false
        end
        for i = 1, 5 do
            local hitbox = attack.hitboxmake(stats.cooldown, stats.tool, stats.alreadyhit, stats.size)
            table.insert(attack.hitboxes, hitbox)
            task.wait(0.05)
        end

    end
end)
print(stats.alreadyhit)```
cedar epoch
#

the module is getting a copy of the bool and when it changes that copy it doesnt affect the original

real patrol
#

I assumed that was the problem, however im not sure how i could fix it?

#

would i keep the value outside the module?

real patrol
real patrol
#

i figured it out