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

How can I stop players from getting killed when they kill zombies?

Asked by 6 years ago
Edited 6 years ago

In my game I have is so that when players touch an enemy with a humanoid part named Zombie, they will latch on to attack the zombie. This works just fine in studio, but when tested online, the player dies when the zombie does with no errors sent to the console. I also tried resetting my character while attached to a zombie a few times but nothing happened then. I think it has to do with the weld that connects the player to the zombie but I don't know why that would kill the player and not the zombie. If anyone knows how to fix this, it would be greatly appreciated. Here is the script that I made...

local grabbing = script.Parent.Latched
local character
local humanoid
local part = script.Parent.HumanoidRootPart
local UserInputService = game:GetService("UserInputService")
script.Parent.HumanoidRootPart.Touched:connect(function(hit)
    zombie = hit.Parent:findFirstChild("Zombie")
    if zombie ~=nil and zombie.Health ~= 0 and grabbing.Value == false then
        grabbing.Value = true
        print("Grab")
        part.CFrame = CFrame.new(part.Position,hit.Position)
        local CJ = CFrame.new(part.Position,hit.Position)
        local C0 = part.CFrame:inverse()*CJ
        local C1 = hit.CFrame:inverse()*CJ
        grip = Instance.new("Weld")
        grip.Name = "Latch"
        grip.C0 = C0
        grip.C1 = C1
        grip.Parent = part
        grip.Part0 = part
        grip.Part1 = hit
    end
end)


while true do
    wait(1)
    if grabbing.Value == true then
        if zombie == nil or zombie.Health == 0 or grip == nil then
            grabbing.Value = false
        end
    end
end

Answer this question