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

Could someone help me make my attack script stop damageing?

Asked by 6 years ago
Edited 6 years ago

Here is the script its not the best but it my try at it im kinda in experienced

This is my full script i tried my best

local animation = Instance.new("Animation")

    animation.AnimationId = "http://www.roblox.com/Asset?id=873178948"
    Player = game.Players.LocalPlayer
 mouse = Player:GetMouse()

local Player = game.Players.LocalPlayer

local Character = Player.Character

local Humanoid = Character:WaitForChild("Humanoid")

local Animation = Instance.new("Animation")

function Hit(damage)
 if damage.Parent:FindFirstChild("Humanoid") and damage.Parent.Name ~=
  Player.Name then
 damage.Parent.Humanoid.Health = damage.Parent.Humanoid.Health -1
 end
 end

local Player = game.Players.LocalPlayer
    local Mouse =  Player:GetMouse()

    local animTrack = nil
    local CanDamage = true
    local CanDamage = false

        CanDamage = false
    Mouse.KeyDown:connect(function(key)
        if key:lower() == "q" then
            local character = Player.Character
            animTrack = character:WaitForChild("Humanoid"):LoadAnimation(animation)
            animTrack:Play()
     Player.Character["Left Arm"].Touched:connect(Hit)
    local CanDamage = false

        end

    end)
0
messy thread , please organise it properly. arshad145 392 — 6y
0
k CaptainJ222 2 — 6y
0
Why do you define "CanDamage" twice? User#5423 17 — 6y
View all comments (8 more)
0
thank you CaptainJ222 2 — 6y
0
I didn't know the site had that :o Thank you for the information ^^ arshad145 392 — 6y
0
lol CaptainJ222 2 — 6y
0
@CaptainJ222 the problem is the way you are using / creating the CanDamage variable. User#5423 17 — 6y
0
please explain CaptainJ222 2 — 6y
0
Where are you connecting the "Hit" function? User#5423 17 — 6y
0
oh umm CaptainJ222 2 — 6y
0
dosnt function Hit(damage) CaptainJ222 2 — 6y

1 answer

Log in to vote
1
Answered by
arshad145 392 Moderation Voter
6 years ago

Hello,

I have tried to help as far as I can because your script is a mess.

Localscript found in Backpack :

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://873178948" --Convert it into an assetid by putting it into a AnimationId slot.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
--local Character = Player.Character -- In studio , everything loads nearly instantly, but on servers there is a delay.
repeat wait() until player.Character -- This creates a loop until the player has fully loaded.
local char = player.Character
local hum = char:findFirstChild("Humanoid")
local animTrack = nil
local CanDamage = true -- Why do you declare both as false and true? 
--The above is a debounce , which prevents the instant death of a Humanoid.


mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        --animTrack = char:WaitForChild("Humanoid"):LoadAnimation(animation)
        --animTrack:Play()
        char["Left Arm"].Touched:Connect(function(hit)
            if (hit.Parent:FindFirstChild("Humanoid")) and (hit.Parent.Name ~= player.Name) and (CanDamage == true) then
                --hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -1 -- Too much effort.
                hit.Parent:findFirstChild("Humanoid"):TakeDamage(1) -- This is the line that damages the Humanoid.
                --If that was what you were searching for.
                CanDamage = false
                wait(1)
                CanDamage = true
            end
        end)
    end

end)

I am still learning RbxLua.

Thank you for reading.

0
Thankyou for trying with my messy work im new a well CaptainJ222 2 — 6y
0
unfortunatly it only dose damage once men this is hard idk why it wont work CaptainJ222 2 — 6y
0
It will do damage after 1 second...Cooldown just change line 24 : wait(delay you want) arshad145 392 — 6y
Ad

Answer this question