Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Gun is damaging Pathfinding NPCs, but its not killing them?

Asked by 6 years ago

So I'm using a raycasting gun and when I fire it at a NPC , the NPC reaches 0 health but doesnt die and keeps following me? Here is the scripts. Oh and by the way they are holding a sword because they are ninjas.

  local tool = script.Parent
    local player = game:GetService("Players").LocalPlayer

    tool.Equipped:connect(function(mouse)
        print("Tool equipped!")

        mouse.Button1Down:connect(function()
            print("Mouse pressed!")
            local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
            local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

            local beam = Instance.new("Part", workspace)
            beam.BrickColor = BrickColor.new("White")
            beam.FormFactor = "Custom"
            beam.Material = "Plastic"
            beam.Transparency = 0.6
            beam.Anchored = true
            beam.Locked = true
            beam.CanCollide = false

            local distance = (tool.Handle.CFrame.p - position).magnitude
            beam.Size = Vector3.new(0.3, 0.3, distance + 5)
            beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

            game:GetService("Debris"):AddItem(beam, 0.1)

            if part then
                local humanoid = part.Parent:FindFirstChild("Humanoid")

                if not humanoid then
                    humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
                end

                if humanoid then
                    script.Parent.Fire:Play()
                                        humanoid:TakeDamage(40)

                end
            end
        end)
    end)

Thanks!

0
u can 1. delete the ninjas upon death or 2. delete the ninja's pathfinding script and play a death animation upon death TheluaBanana 946 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

I believe this is due to your game having FilteringEnabled on, it means that anything that the Client does cannot affect anything on the server, in this case the NPC. This means that no one else in the game can see this change, only the Client. This is so that the game can attempt to stop exploiters and trolls inserting inappropriate images into the game. Instead, the Client would request for things to happen for the server to do, for example the Client requesting the NPC to be damaged by the sword.

With your script, the Client appears to have changed the NPCs health, but that's only to the Client, not to the server. The server still thinks the NPC's health has not changed. Below is a link regarding Filtering Enabled being discussed:

https://devforum.roblox.com/t/how-do-i-even-go-about-using-filtering-enabled/150072

Hope this helps a bit!

0
oki doki! I'll disable filtering enabled as it is a single player game! nzsalty16 81 — 6y
0
I suggest that you don't if you plan on making the game popular, Roblox severely likes the idea of having exploitable games. Although you can still learn scripts, you just need to learn how to convert them so it works with FilteringEnabled. Marmalados 193 — 6y
0
umm... I disabled flitering enabled. However, the Pathfinding NPC holding the sword wont die even when it has 0 health nzsalty16 81 — 6y
0
to my understanding disabling filtering enabled doesnt truly do anything, things that are affected by FE still wont work DinozCreates 1070 — 6y
Ad

Answer this question