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

Attack script works on NPCs but does not work on players?

so i got this script that damages players, and makes a part that welds to the damaged player then the part welds to your hand, and its just used for looks but it doesn't work on players at all. It works on npcs 100% of the time but for players it completely ignores them and just does the damage part. Heres a stripped down version of my code:

local Part = enemyplayer.Character.HumanoidRootPart --(placeholder)
local player = Nikkted -- me
local humanoidRootpart = Nikkted.Character.HumanoidRootPart

	spawn(function()
		local explosionPart = Instance.new("Part", player.Character)
		explosionPart.Parent = player.Character
		explosionPart.Anchored = false
		explosionPart.Massless = true
		explosionPart.CanCollide = false
		explosionPart.Size = Vector3.new(0.616, 0.104,30)
		explosionPart.BrickColor = BrickColor.new("New Yeller")
		explosionPart.Material = Enum.Material.Neon
		explosionPart.Transparency = 0
		explosionPart.CFrame = 					 player.Character.HumanoidRootPart.CFrame*CFrame.new(0,1,-89)
		local weld = Instance.new("Weld",player.Character.RightHand)
		weld.Part1 = player.Character.RightHand
		weld.Part0 = explosionPart
		weld.C0 = CFrame.new(0,0,15)*CFrame.Angles(math.pi/2,math.pi,0)
		local attachment0 = Instance.new("Attachment",explosionPart)
		attachment0.Position = Vector3.new(0,0,15)
		local attachment1 = Instance.new("Attachment",explosionPart)
		attachment1.Position = Vector3.new(0,0,-15)
		local Stars = script.Stars:Clone()
		Stars.Parent = explosionPart
		local trail = script.Trail:Clone()
		trail.Parent = explosionPart
		trail.Attachment0 = attachment0
		trail.Attachment1 = attachment1
		part.Parent = player.Character
		part.Anchored = false
		part.Massless = true
		part.CanCollide = false
		part.CFrame = player.Character.RightHand.CFrame
		local weld = Instance.new("Weld",player.Character.RightHand)
		weld.Part1 = player.Character.RightHand
		weld.Part0 = part
		weld.C0 = CFrame.new(0,0,0)]]
								
		local particle = script.Inside:Clone()
		particle.Parent = player.Character.RightHand.Right
		game.Debris:AddItem(particle,2)
								
		for _,v in pairs(Part.Parent:GetDescendants()) do
			if v:IsA("BasePart") then
				--v:SetNetworkOwner(plr)
				v.Massless = true
			end
		end
								
		local Weld = Instance.new("ManualWeld")
		Weld.Name = "DetainWeld"
		Weld.Parent = explosionPart
		Weld.Part0, Weld.Part1 = Weld.Parent, Part.Parent.PrimaryPart
		Weld.C0 = Weld.Parent.CFrame:inverse()
		Weld.C1 = CFrame.new((Weld.Parent.Position + Weld.Parent.CFrame.LookVector * 3), Weld.Parent.Position + Weld.Parent.CFrame.LookVector):inverse()
		game.Debris:AddItem(Weld,3)
		local anim = Part.Parent.Humanoid:LoadAnimation(script.Stun)
		anim:Play()
								
		local player2 = game.Players:GetPlayerFromCharacter(enemyHumanoid.Parent)
		if player2 ~= nil then
									game.ReplicatedStorage.StunRemote:FireClient(player2,false)
		end
								
		spawn(function()
			wait(.8)
			for i = 1,20 do
				wait()
				explosionPart.Transparency = explosionPart.Transparency+(0.05)
			end
			wait(.15)
			explosionPart:Destroy()
			weld:Destroy()
		end)
		wait(.9)
		local sound = script.Knockback:Clone()
		sound.Volume = 1
		sound.Parent = Part.Parent.Head
		sound:Destroy()
		wait(.475)
		particle:Destroy()
		Weld:Destroy()
								
		for _,v in pairs(Part.Parent:GetDescendants()) do
			if v:IsA("BasePart") then
				--v:SetNetworkOwner(plr)
				v.Massless = false
			end
		end							
		Part.Parent.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-10)
		local bodyVelocity = Instance.new("BodyVelocity", Part.Parent.HumanoidRootPart)
		bodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bodyVelocity.Velocity = CFrame.new(humanoidRootPart.Position, mouseHit).lookVector * 100	
		game.Debris:AddItem(bodyVelocity,.6)
		wait(.5)
		bodyVelocity:Destroy()
		explosionPart:Destroy()
		anim:Stop()
	end)							
-------------------------------			
	if enemyHumanoid and enemyHumanoid.Health > 0 then
		enemyHumanoid:TakeDamage(100)
	end
-------------------------------

i don't see where the barrier between whats a player and whats an npc stops it from working on players is it because welding players to players doesn't work or something? idk if I'm missing something but I hope you guys could help me out <3

1 answer

I Found This Script In A Zombie it works, If You Want To Change Costume Then Just Add Different Heads etc. local zombie = script.Parent

for _, script in pairs(zombie.ModuleScripts:GetChildren()) do if not game.ServerStorage:FindFirstChild(script.Name) then script:Clone().Parent = game.ServerStorage end end

local AI = require(game.ServerStorage.ROBLOX_ZombieAI).new(zombie) local DestroyService = require(game.ServerStorage.ROBLOX_DestroyService)

local function clearParts(parent) for _, part in pairs(parent:GetChildren()) do clearParts(part) end local delay if parent:IsA("Part") then delay = math.random(5,10) else delay = 11 end DestroyService:AddItem(parent, delay) end

zombie.Humanoid.Died:connect(function() AI.Stop() math.randomseed(tick()) clearParts(zombie) script.Disabled = true end)

local lastMoan = os.time() math.randomseed(os.time()) while true do local animationTrack = zombie.Humanoid:LoadAnimation(zombie.Animations.Arms) animationTrack:Play() -- local now = os.time() -- if now - lastMoan > 5 then -- if math.random() > .3 then -- zombie.Moan:Play() ---- print("playing moan") -- lastMoan = now -- end -- end wait(2) end

`

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