Make npc i made attack you with magic

Ah sorry, you were casting from the Player’s Character to the NPC, not the other way around. Try this:

local ray = Ray.new(npcToFind.HumanoidRootPart.CFrame.p, (npcToFind.HumanoidRootPart.CFrame.p - char.HumanoidRootPart.CFrame.p).unit * 300)
1 Like

it shooting backwards now, and prints “Part found” and don’t do any damage

1 Like

i fixed the shooting backwards thing, but it’s still doesn’t do any damage

1 Like

Check if it even finds a Humanoid, because that might be the problem.

1 Like

ok i fixed it, now it works , i want to make the hand disappear after did a move, and appear again if it’s about to do another move , how i do that?
i tried to do :Clone at the start and :Destroy and the end but it’s just disappears forever after the destroy, so what i do with this?

-- Clone the original hand and save it as ClonedHand
local ClonedHand = Hand:Clone()
-- IMPORTANT: Destroy the cloned hand, not the original
ClonedHand:Destroy()

it’s still destroys forever, and also theres a bug with my thing that sometimes if you hold weapon, it hits the weapon and the humanoid doesn’t take damage

i tried this:

local char = script.Parent
local npcToFind = workspace.Gaster

local Moves = {
    function(TargetPlayer)
		local attk = game.ReplicatedStorage.attacks["Gaster Hand"]:Clone()
		attk.Parent = workspace
        local ray = Ray.new(attk["Hole Part"].CFrame.p, (char.HumanoidRootPart.CFrame.p - attk["Hole Part"].CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, char, false, true)
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Bright red")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		
		local distance = 400
		beam.Size = Vector3.new(3, 3, distance)
		beam.CFrame = CFrame.new(attk["Hole Part"].CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		
		game:GetService("Debris"):AddItem(beam, 0.6)
		local hit,pos,normal = workspace:FindPartOnRay(ray)
		if hit and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(1)
			attk:Destroy()
		else
			print(hit.Name)
			attk:Destroy()
		end
        return 2 -- The time in seconds you want to wait before the next attack
    end,
    function(TargetPlayer)
		local attk = game.ReplicatedStorage.attacks["Gaster Hand"]:Clone()
		attk.Parent = workspace
        local ray = Ray.new(attk["Hole Part"].CFrame.p, (char.HumanoidRootPart.CFrame.p - attk["Hole Part"].CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, char, false, true)
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Bright blue")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		
		local TO = char.HumanoidRootPart
		local distance = 400
		beam.Size = Vector3.new(3, 3, distance)
		beam.CFrame = CFrame.new(attk["Hole Part"].CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		
		game:GetService("Debris"):AddItem(beam, 0.6)
		local hit,pos,normal = workspace:FindPartOnRay(ray)
		if hit and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(1)
			attk:Destroy()
		else
			print(hit.Name)
			attk:Destroy()
		end
        return 2 -- The time in seconds you want to wait before the next attack
    end
}

local function GetRandomMove()
    return Moves[math.random(#Moves)]
end

local lastAttack = 0

spawn(function()
	while true do
		local TO = char.HumanoidRootPart
		local dist = (TO.Position - npcToFind.HumanoidRootPart.Position).magnitude
		if dist <= 50 then
			npcToFind.HumanoidRootPart.CFrame = CFrame.new(npcToFind.HumanoidRootPart.Position, char.HumanoidRootPart.Position*Vector3.new(1,0,1) + char.HumanoidRootPart.Position*Vector3.new(0, 1, 0))
            if lastAttack <= tick() then
                local Move = GetRandomMove()
                local returnedTime = Move(game.Players:GetPlayerFromCharacter(char))
                lastAttack = tick() + returnedTime
            end
		end
		wait()
	end
end)

is there a way to get all parts that the ray hit in the distance and if one of them was humanoid then the humanoid will take damage?

So, it’s really nice of @SimplyData to have helped you with this, but for future, #development-support:scripting-support is generally for getting help with pre-exisiting script, not for asking people to write code for you.

1 Like

oh ok, sorry… then where i can ask these kind of questions?

If you wanted to hire someone to write the code for you, you could post in #public-collaboration but the DevForum isn’t really for getting people to write you free scripts, so I’m not sure where you can post for that.

1 Like

There is no place on the DevForum for those kinds of threads. Public Collaboration to hire someone to do that or ask elsewhere that isn’t the DevForum.

1 Like

That’s about what I was thinking. Thanks for confirming for us.