Categories > Coding > Lua >

Why doesnt it deal damage

Posts: 45

Threads: 18

Joined: Aug, 2022

Reputation: 2

Posted

Ok so i made this script that goes inside a tool and when used it punches. I wanted to make it so that npcs have a value that makes it so you can attack them but players have the same value but it makes it so you cant attack them. For some reason it doesnt work, The value is "CanHit" and the thing that isnt working is at line 194 in the code

local rp = game:GetService("ReplicatedStorage")
local combatevent = script.Parent
local animation = script:WaitForChild("Animations")
local acutalplayer = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local tweenService = game:GetService("TweenService")
local ALIVE_TAG_NAME = "Punch"




local anims = {
	animation:WaitForChild("Left"), --Add more animations here
	animation:WaitForChild("Right"),
	animation:WaitForChild("Left2"),
	animation:WaitForChild("Kick")

}

combatevent.OnServerEvent:Connect(function(player,count,V1)
	local character = player.Character
	local Hum = character:WaitForChild("Humanoid")

	spawn(function()
		Hum.WalkSpeed = 10
		wait(3)
		Hum.WalkSpeed = 16
	end)


	local clash = Instance.new("BoolValue")
	clash.Name  = "ClashAttack"
	clash.Value = false
	clash.Parent = player.Character
	game.Debris:AddItem(clash,0.4)







	local dodge = {11533475674,11533477174,11533479107} --paste animation id here
	local num = math.random(#dodge)
	local chosenanim = dodge[num]




	local attack = Hum:LoadAnimation(anims[count])
	attack:Play()

	combatevent:FireClient(player)

	local hiteffectball = function(target,pos)

		local hiteffect = game.ReplicatedStorage.Combat.Thing:Clone()
		hiteffect.CFrame = pos
		hiteffect.CFrame =  CFrame.new(hiteffect.Position, target.Position) 		
		hiteffect.Parent = target
		game.Debris:AddItem(hiteffect,1)



		if count == 4 then
			hiteffect.BrickColor = BrickColor.new("Neon orange")
		end

		tweenService:Create(hiteffect,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{CFrame = hiteffect.CFrame + hiteffect.CFrame.lookVector * -7,Transparency = 1,Size = Vector3.new(0.087, 0.08, 3.35)}):Play()

	end






	local region = Region3.new(V1-Vector3.new(2,2,2),V1+Vector3.new(2,2,2))
	local RTable = workspace:FindPartsInRegion3(region,nil,20)

	for i,v in pairs(RTable) do
		if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= character then
			local deb = Instance.new("BoolValue",v.Parent)
			deb.Name = "Deb"
			game.Debris:AddItem(deb,0.2)
			local closecharacter = v.Parent


			if closecharacter.HumanoidRootPart:FindFirstChild("Block") then
				if (closecharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude < 3.5 then


					local hiteffect = game.ReplicatedStorage.Combat:WaitForChild("HitCollision"):Clone()
					hiteffect.CFrame = closecharacter.HumanoidRootPart.CFrame
					hiteffect.Parent = workspace
					game.Debris:AddItem(hiteffect,0.6)

					local info3 = TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
					local goal3 = {}
					goal3.Size = hiteffect.Size * 12
					goal3.Transparency = 1
					local tween3 = tweenService:Create(hiteffect,info3,goal3)
					tween3:Play()

					
					if count == 4 then
						closecharacter.BlockBar.Value = closecharacter.BlockBar.Value - 100


						local bv = Instance.new("BodyVelocity",closecharacter.HumanoidRootPart)
						bv.MaxForce = Vector3.new(1e8,1e8,1e8)
						bv.Velocity = character.HumanoidRootPart.CFrame.lookVector*20
						game.Debris:AddItem(bv,0.3) 
					end	



				else
					
					if 	(closecharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude < 7 then	
						closecharacter.Humanoid:TakeDamage(5)


						local hitvalue = Instance.new("BoolValue")
						hitvalue.Name = "Hit"
						hitvalue.Parent = closecharacter
						game.Debris:AddItem(hitvalue,1)



						local times = 0
						repeat
							times = times + 1
							hiteffectball(closecharacter.HumanoidRootPart,closecharacter.HumanoidRootPart.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
						until times >= 4


						local GoreFX = game.ReplicatedStorage.Combat.Gore:Clone()
						GoreFX.Parent = closecharacter.HumanoidRootPart
						GoreFX:Emit(1)
						game.Debris:AddItem(GoreFX,1)

						local Sound = Instance.new("Sound")
						Sound.SoundId = "rbxassetid://3932506183"
						Sound.Parent = closecharacter.HumanoidRootPart
						Sound.PlaybackSpeed = math.random(93,107)/100
						Sound:Play()
						game.Debris:AddItem(Sound,0.5)	


						if count == 4 then


							local Track11= Instance.new("Animation")
							Track11.AnimationId = "rbxassetid://11533482823"
							local Anim11 = closecharacter.Humanoid:LoadAnimation(Track11)
							Anim11:Play()

							local bv = Instance.new("BodyVelocity",closecharacter.HumanoidRootPart)
							bv.MaxForce = Vector3.new(1e8,1e8,1e8)
							bv.Velocity = character.HumanoidRootPart.CFrame.lookVector*30
							game.Debris:AddItem(bv,0.3) 
							Anim11:Stop()


							local Sound = Instance.new("Sound")
							Sound.SoundId = "rbxassetid://3932506183"
							Sound.Parent = closecharacter.HumanoidRootPart
							Sound.PlaybackSpeed = math.random(93,107)/100
							Sound:Play()
							game.Debris:AddItem(Sound,0.5)	

						end

						spawn(function()
							closecharacter.Humanoid.WalkSpeed = 1
							closecharacter.Humanoid.JumpPower = 1		
							wait(1.7) 
							closecharacter.Humanoid.WalkSpeed = 16
							closecharacter.Humanoid.JumpPower = 50

						end)



					end
				end



			else


				local CanHit = closecharacter.Humanoid.CanHit
				if CanHit == true then
					
				
					closecharacter.Humanoid:TakeDamage(7)


					local times = 0
					repeat
						times = times + 1
						hiteffectball(closecharacter.HumanoidRootPart,closecharacter.HumanoidRootPart.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
					until times >= 4

					local closeplayer = game.Players:GetPlayerFromCharacter(closecharacter)



					local hitvalue = Instance.new("BoolValue")
					hitvalue.Name = "Hit"
					hitvalue.Parent = closecharacter
					game.Debris:AddItem(hitvalue,1)



					local GoreFX = game.ReplicatedStorage.Combat.Gore:Clone()
					GoreFX.Parent = closecharacter.HumanoidRootPart
					GoreFX:Emit(1)
					game.Debris:AddItem(GoreFX,1)

					local Sound = Instance.new("Sound")
					Sound.SoundId = "rbxassetid://3932506183"
					Sound.Parent = closecharacter.HumanoidRootPart
					Sound.PlaybackSpeed = math.random(93,107)/100
					Sound:Play()
					game.Debris:AddItem(Sound,0.5)
				elseif CanHit == false then
					print("no")



					if count == 4 then


						local Track11= Instance.new("Animation")
						Track11.AnimationId = "rbxassetid://11533485728"
						local Anim11 = closecharacter.Humanoid:LoadAnimation(Track11)
						Anim11:Play()

						local bv = Instance.new("BodyVelocity",closecharacter.HumanoidRootPart)
						bv.MaxForce = Vector3.new(1e8,1e8,1e8)
						bv.Velocity = character.HumanoidRootPart.CFrame.lookVector*30
						game.Debris:AddItem(bv,0.3) 
						Anim11:Stop()


						local sound = Instance.new("Sound")
						sound.SoundId = "rbxassetid://4810749120"
						sound.Parent = closecharacter.HumanoidRootPart
						sound.PlaybackSpeed = math.random(93,107)/100
						sound:Play()
						game.Debris:AddItem(sound,3)

					end




					spawn(function()
						closecharacter.Humanoid.WalkSpeed = 1
						closecharacter.Humanoid.JumpPower = 1		
						wait(1.7) 
						closecharacter.Humanoid.WalkSpeed = 16
						closecharacter.Humanoid.JumpPower = 50

					end)
				end
			end
		end
	end




end)
  • 0

superleito1_1

i like chicken nuggets

vip

Posts: 61

Threads: 16

Joined: Jun, 2022

Reputation: 6

Replied

why not rename the humanoid of the npc instead of using a value? waste of time

  • 0

"""""""professional""""""" at code

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )