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

Why this script it's not doing damage to NPC/Bosses ?

I need this beam to deal damage to dummies and not player this dummies have a value inside the humanoid called NPC that i setted true

script.Parent.OnServerEvent:Connect(function(plr)
	local TweenService = game:GetService("TweenService")
	local Bls = game.ReplicatedStorage.BlasterSoul.Head:Clone()
	Bls.Parent = workspace
	Bls.CanCollide = false
	Bls.Anchored = false
	Bls.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,1,-5) * CFrame.fromEulerAnglesXYZ(math.rad(37),math.rad(0),math.rad(0))
	wait()
	Bls.Anchored = true
	local CHARGING = TweenService:Create(Bls.Charging, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 0, Size = Vector3.new(2,2,2)})
	CHARGING:Play()
	CHARGING.Completed:Wait()
	Bls.boomer.Transparency = 0.5
	local Beam1 = TweenService:Create(Bls.boomer, TweenInfo.new(1,Enum.EasingStyle.Linear), {Transparency = 0.5, Size = Vector3.new(130.864, 2.4, 2.8)})
	Beam1:Play()
	Beam1.Completed:Wait()
	Bls.Charging:Destroy()
	Bls.boomer.Beam1.Enabled = true
	Bls.boomer.Beam2.Enabled = true
	Bls.boomer.Beam3.Enabled = true
	local Beam2 = TweenService:Create(Bls.boomer, TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,19, true), {Size = Vector3.new(130.864, 3.2, 3.2)})
	Beam2:Play()
	Beam2.Completed:Wait()
	Bls.boomer.Beam1.Enabled = false
	Bls.boomer.Beam2.Enabled = false
	Bls.boomer.Beam3.Enabled = false
	local Beam3 = TweenService:Create(Bls.boomer, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Size = Vector3.new(130.864, 0.001, 0.001)})
	Beam3:Play()
	Beam3.Completed:Wait()
	Bls.boomer:Destroy()
	local AdiosHead = TweenService:Create(Bls, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Position + Vector3.new(0,10,0)})
	local AdiosEye1 = TweenService:Create(Bls.LeftEye, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.LeftEye.Position + Vector3.new(0,10,0)})
	local AdiosEye2 = TweenService:Create(Bls.RightEye, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.RightEye.Position + Vector3.new(0,10,0)})
	local AdiosJaws1 = TweenService:Create(Bls.Jaws.rja, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Jaws.rja.Position + Vector3.new(0,10,0)})
	local AdiosJaws2 = TweenService:Create(Bls.Jaws.LJA, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Jaws.LJA.Position + Vector3.new(0,10,0)})
	local AdiosUnion = TweenService:Create(Bls.Union, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Union.Position + Vector3.new(0,10,0)})
	local AdiosInside = TweenService:Create(Bls.Inside2, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Inside2.Position + Vector3.new(0,10,0)})
	AdiosHead:Play()
	AdiosEye1:Play()	
	AdiosEye2:Play()
	AdiosJaws1:Play()
	AdiosJaws2:Play()
	AdiosUnion:Play()
	AdiosInside:Play()
	Bls:Destroy()
	Bls.boomer.Touched:Connect(function(hit)
		local hum = hit.parent:FindFirstChildOfClass("Humanoid")
		if hum and hum.NPC.Value == true then
				hum:TakeDamage(1)
		end
	end)
end)

1 answer

✓ Accepted answer

It's probably because you're connecting the event after it was destroyed. Also, to check if a character is an NPC, you can use Players:GetPlayerFromCharacter() and if it returns nil it's not a real player.

script.Parent.OnServerEvent:Connect(function(plr)
	local Players = game:GetService("Players")
	local TweenService = game:GetService("TweenService")
	local Bls = game.ReplicatedStorage.BlasterSoul.Head:Clone()
	Bls.Parent = workspace
	Bls.boomer.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
		local playerNPC = Players:GetPlayerFromCharacter(hit.Parent)
		if (hum ~= nil) and (playerNPC == nil) then
			hum:TakeDamage(1)
		end
	end)
	Bls.CanCollide = false
	Bls.Anchored = false
	Bls:PivotTo(plr.Character.HumanoidRootPart:GetPivot() * CFrame.new(0,1,-5) * CFrame.Angles(math.rad(37), 0, 0))
	task.wait()
	Bls.Anchored = true
	local CHARGING = TweenService:Create(Bls.Charging, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 0, Size = Vector3.new(2,2,2)})
	CHARGING:Play()
	CHARGING.Completed:Wait()
	Bls.boomer.Transparency = 0.5
	local Beam1 = TweenService:Create(Bls.boomer, TweenInfo.new(1,Enum.EasingStyle.Linear), {Transparency = 0.5, Size = Vector3.new(130.864, 2.4, 2.8)})
	Beam1:Play()
	Beam1.Completed:Wait()
	Bls.Charging:Destroy()
	Bls.boomer.Beam1.Enabled = true
	Bls.boomer.Beam2.Enabled = true
	Bls.boomer.Beam3.Enabled = true
	local Beam2 = TweenService:Create(Bls.boomer, TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,19, true), {Size = Vector3.new(130.864, 3.2, 3.2)})
	Beam2:Play()
	Beam2.Completed:Wait()
	Bls.boomer.Beam1.Enabled = false
	Bls.boomer.Beam2.Enabled = false
	Bls.boomer.Beam3.Enabled = false
	local Beam3 = TweenService:Create(Bls.boomer, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Size = Vector3.new(130.864, 0.001, 0.001)})
	Beam3:Play()
	Beam3.Completed:Wait()
	Bls.boomer:Destroy()
	local AdiosHead = TweenService:Create(Bls, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Position + Vector3.new(0,10,0)})
	local AdiosEye1 = TweenService:Create(Bls.LeftEye, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.LeftEye.Position + Vector3.new(0,10,0)})
	local AdiosEye2 = TweenService:Create(Bls.RightEye, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.RightEye.Position + Vector3.new(0,10,0)})
	local AdiosJaws1 = TweenService:Create(Bls.Jaws.rja, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Jaws.rja.Position + Vector3.new(0,10,0)})
	local AdiosJaws2 = TweenService:Create(Bls.Jaws.LJA, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Jaws.LJA.Position + Vector3.new(0,10,0)})
	local AdiosUnion = TweenService:Create(Bls.Union, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Union.Position + Vector3.new(0,10,0)})
	local AdiosInside = TweenService:Create(Bls.Inside2, TweenInfo.new(2,Enum.EasingStyle.Linear), {Transparency = 1, Position = Bls.Inside2.Position + Vector3.new(0,10,0)})
	AdiosHead:Play()
	AdiosEye1:Play()    
	AdiosEye2:Play()
	AdiosJaws1:Play()
	AdiosJaws2:Play()
	AdiosUnion:Play()
	AdiosInside:Play()
	Bls:Destroy()
end)

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