Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Could someone help me make my attack script stop damageing?

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)

12 comments

0

messy thread , please organise it properly.

0

k

0

Why do you define "CanDamage" twice?

0

thank you

0

I didn't know the site had that :o Thank you for the information ^^

0

lol

0

@CaptainJ222 the problem is the way you are using / creating the CanDamage variable.

0

please explain

0

Where are you connecting the "Hit" function?

0

oh umm

0

dosnt function Hit(damage)

1 answer

✓ Accepted answer

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.

3 comments

0

Thankyou for trying with my messy work im new a well

0

unfortunatly it only dose damage once men this is hard idk why it wont work

0

It will do damage after 1 second...Cooldown just change line 24 : wait(delay you want)

This discussion is preserved as it was. New answers, comments, and votes are closed.