#fucking script aint working

1 messages · Page 1 of 1 (latest)

little lake
#

i am not taking damage for some fucking reason

#
local db = false

game.ReplicatedStorage.RemoteEvents.Weapons.ExplodeGrenade.OnServerEvent:Connect(function(plr, part)
    local ok = Instance.new("Explosion")
    ok.Position = part.Position
    ok.Parent = workspace
    ok.BlastRadius = 500000
    ok.BlastPressure = 0
    ok.DestroyJointRadiusPercent = 0 
    part:Destroy()
    print(ok.Name)
    
    ok.Hit:Connect(function(hitPart, distance)
        if db then return end
        db = true
        local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChildWhichIsA("Humanoid")
        if humanoid and humanoid.Health > 0 then
            print("Hit", humanoid.Parent.Name, "at distance", distance)
            
            local maxDamage = 80
            local maxRadius = 30

            local damage = 0
            if distance <= maxRadius then
                damage = math.floor(maxDamage * (1 - distance / maxRadius))
                damage = math.max(damage, 0) 
            end
            
            if damage > 0 then
                humanoid:TakeDamage(damage)
            end
        end
        
        task.wait(2)
        db = false
    end)
end)

--ok
ember vale
little lake
#

sometimes the distance thingy doesnt print but sometimes it does

#

lemme test again

#

one sec

#

ok yea doesnt print anything now

#

well if were talking abt the ok.Hit part but the others print

ember vale
little lake
#

yea its at the bottom

#

after the task.wait(2)

ember vale
little lake
#

i have another script that that has a cooldown so after clicking once u got a 45 sec cool down so i gotta rerun the game

#

also i think i know what the problem is

ember vale
#

Alrighty, then it's this line local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChildWhichIsA("Humanoid")

little lake
#

could be that i gotta put the ok.Hit:Connect(function() before it gets put in the workspace

#

lemme print Humanoid to make sure

ember vale
#

It could hit an accessory, then it will have activated the db, while hitPart.Parent = the accessory

#

(or well, the part inside an accessory, as accessories are technically just data)

little lake
#

ok yea i tested it and u were right bc its not finding a humanoid

hot thunderBOT
#

studio** You are now Level 2! **studio

ember vale
#

I would just replace the line with
local humanoid = hitPart.Parent.Humanoid or hitPart.Parent.Parent.Humanoid

#

Just make sure that it doesn't error, I doubt that hitPart.Parent = nil (as that would mean that it hits some nilinstance somehow), yet better safe than sorry

little lake
#

ok i got it working but had to go with a whole different method