#Hit not working

1 messages · Page 1 of 1 (latest)

dapper creek
#
game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(plr)
    spawn(function()
        plr.Character.Humanoid.WalkSpeed = 7
        task.wait(.35)
        plr.Character.Humanoid.WalkSpeed = 16
    end)
    
    local hitbox = Instance.new("Part")
    
    hitbox.Parent = workspace
    hitbox.CanCollide = false
    hitbox.Anchored = true
    hitbox.Size = Vector3.new(6,6,6)
    hitbox.BrickColor = BrickColor.new("Really red")
    hitbox.Transparency = .5
    hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-3)
    game.Debris:AddItem(hitbox,1)
    
    
    
    
    
    
    
    local hitboxCooldown = false
    hitbox.Touched:Connect(function(hit)
    if hit.Parent.Name ~= plr.Name and plr.Parent:FindFirstChild("Humanoid") then
        if hitboxCooldown == true then return end
        hitboxCooldown = true
        
        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
        local vfx = game.ReplicatedStorage.HitVFX.Attachment:Clone()
        vfx.Parent = hit.Parent.HumanoidRootPart
        local sound = script.slash:Clone()
        sound.Parent = hit.Parent.HumanoidRootPart
        sound:Play()
        game.Debris:AddItem()
        spawn(function()
            for i,v in vfx:GetChildren() do
                if v:IsA("ParticleEmitter") then
                    v:Emit(v:GetAttribute("EmitCount"))
                end
            end
        end)
        game.Debris:AddItem(vfx,1.5)
        task.wait(1)
        hitboxCooldown = false
        
    end
    end)
    
end)
#

It won't hit anything

#

if I mess with the code that stops me from hitting myself then I am able to hit myself and not others

#

Specifically if I do

game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(plr)
    spawn(function()
        plr.Character.Humanoid.WalkSpeed = 7
        task.wait(.35)
        plr.Character.Humanoid.WalkSpeed = 16
    end)
    
    local hitbox = Instance.new("Part")
    
    hitbox.Parent = workspace
    hitbox.CanCollide = false
    hitbox.Anchored = true
    hitbox.Size = Vector3.new(6,6,6)
    hitbox.BrickColor = BrickColor.new("Really red")
    hitbox.Transparency = .5
    hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-3)
    game.Debris:AddItem(hitbox,1)
    
    
    
    
    
    
    
    local hitboxCooldown = false
    hitbox.Touched:Connect(function(hit)
    if hit.Parent.Name ~= plr.Parent:FindFirstChild("Humanoid") then
        if hitboxCooldown == true then return end
        hitboxCooldown = true
        
        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
        local vfx = game.ReplicatedStorage.HitVFX.Attachment:Clone()
        vfx.Parent = hit.Parent.HumanoidRootPart
        local sound = script.slash:Clone()
        sound.Parent = hit.Parent.HumanoidRootPart
        sound:Play()
        game.Debris:AddItem()
        spawn(function()
            for i,v in vfx:GetChildren() do
                if v:IsA("ParticleEmitter") then
                    v:Emit(v:GetAttribute("EmitCount"))
                end
            end
        end)
        game.Debris:AddItem(vfx,1.5)
        task.wait(1)
        hitboxCooldown = false
        
    end
    end)
    
end)

It will let the player hit themselves but not others

ember mirage
#

is this

#

from that one tutorial

dapper creek
#

nevermind it will let them hit others but I need them to not be able to hit themselves

ember mirage
#

because i actually did the same thing, and it worked just fine for me

#

(except without the vfx parts because i didnt bother to put any assets in)

#

would you like me to share my hitbox code real fast?

dapper creek
#

sure

ember mirage
#
    local hitbox = Instance.new("Part")
    
    hitbox.Parent = workspace
    hitbox.CanCollide = false
    hitbox.Anchored = true
    hitbox.Size = Vector3.new(5, 5, 5)
    hitbox.BrickColor = BrickColor.new("Really red")
    hitbox.Transparency = .5
    hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -4)
    game.Debris:AddItem(hitbox, 1)
    
    
    
    local hitboxcooldown = false
    hitbox.Touched:Connect(function(hit)
        if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") then
            if hitboxcooldown == true then return end
            hitboxcooldown = true
            local hit_person = hit.Parent:FindFirstChild("Humanoid")
            if hit_person:GetAttribute("IsBlocking") == false then
                print(plr.Name .. " Hit " .. hit_person.Parent.Name .. " While IsBlocking was " .. tostring(hit_person:GetAttribute("IsBlocking")))
                hit_person:TakeDamage(5)
                hit_person.WalkSpeed = 7
                task.wait(5)
                hit_person.WalkSpeed = 16
                
            else
                print(plr.Name .. " Hit " .. hit_person.Parent.Name .. " While IsBlocking was " .. tostring(hit_person:GetAttribute("IsBlocking")))
                
            end
        end
    end)
    
end)
#

obviously, with some added stuff

#

get rid of the "Isblocking" stuff

#

and it should work just fine

atomic sonnet
#

isn’t plr the player itself? you need to add plr.character.. also im mobile so thats hard asf to read I might be wrong

ember mirage
#

i did the exact same tutorial as them

dapper creek
#

got it

atomic sonnet
#

best way to debug is adding a ton of print statements, so that you will isolate the error. Seems you jumped the gun posting this to a forum but it’s fair as you’re learning

ember mirage
ember mirage
#

i had this one script that fired a remote event that printed something

#

and it printed 3 times on one trigger and i was so confused

#

and then i posted it into a forum and people said there was nothing wrong with it

#

it turns out that the roblox ai literally made 2 seperate copies of the script

#

and it was all firing at the same time

atomic sonnet
#

💀💀 that ai is the death of all scripters

stark notchBOT
#

studio** You are now Level 4! **studio

ember mirage
#

AND I DID SO MUCH WORK TYRING TO FIGURE OUT

#

WHAT WAS WRONG WITH IT

atomic sonnet
#

that’s not as bad as when i was making a system to log server console logs, and put the log function in a loop.. and with how studio works everything is a server console error so it bricked my studio every time i launched the game

#

We always screw ourselves somehow 🤣

ember mirage
#

the while true without a wait clause

#

is a canon event for every scripter

dapper creek
#

I found a new issue 😦

ember mirage
#

hm?

dapper creek
#

my particles aren't disappearing and they appear on random hits and aren't consistant

atomic sonnet
#

particle effects are a pain in the ass

ember mirage
#

yeah

atomic sonnet
#

am i allowed to say that

ember mirage
#

um

#

maybe you can

#

add the debris to the part

#

that creates the vfx

#

im just taking a shot in the dark here i have no idea how to do vfx

atomic sonnet
#

if you disable them they don’t instantly disappear, if I recall even deleting them doesn’t. Only way to remove it instantly is moving the part the particles are connected to

#

^ that’s the ghetto fix i learned there’s probably a more efficient way to do it

ember mirage
#

my entire game so far is just the ghetto fix

#

😭

atomic sonnet
#

😭🤣 We all do it

ember mirage
#

if it works it works

atomic sonnet
#

then you learn how to do it the “proper” way and it’s a slap in the face

ember mirage
#

i was struggling until i learned how to use attributes

atomic sonnet
#

Oh yeah they’re very useful, i used to abuse them until I learned module scripts

ember mirage
#

im still on the whole module script thing

stark notchBOT
#

studio** You are now Level 5! **studio

atomic sonnet
#

They have infinite uses I can’t go back anymore, any system I make is modular in some way