#dont cause damage

5 messages · Page 1 of 1 (latest)

random crystal
#

Help me

hushed basalt
#

local player = game.Players.LocalPlayer

local function DealDamageToNPCs()
local leaderstats = player:WaitForChild("leaderstats")
local energy = leaderstats:WaitForChild("Energy")
local damageAmount = energy.Value

local character = player.Character
if character then
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        local rayStart = character.Head.Position
        local rayEnd = rayStart + (character.Head.CFrame.LookVector * 10)  
        
        local hitPart, hitPosition = workspace:FindPartOnRayWithWhitelist(Ray.new(rayStart, rayEnd - rayStart), {workspace.NPCFolder})
        if hitPart then
            local npcHumanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
            if npcHumanoid then
                print("NPC atingido!")
                if npcHumanoid.Health > 0 then
                    npcHumanoid:TakeDamage(damageAmount)
                    print("Damage caused in NPCs!")
                else
                    print("NPC it's already dead.")
                end
            else
                print("NPC dont have Humanoid.")
            end
        else
            print("None NPC reaching.")
        end
    else
        print("Player dont have Humanoid.")
    end
else
    print("Player not in the game.")
end

end

local function ButtonClicked()
DealDamageToNPCs()
end

local button = script.Parent.ClickButton
button.MouseButton1Click:Connect(ButtonClicked)

severe sealBOT
#

studio** You are now Level 1! **studio

hushed basalt
#

move the local variable into the function

random crystal