local humanoid = script.Parent:WaitForChild("Humanoid") local player = game:GetService("Players").LocalPlayer humanoid.Died:Connect(function() player:Kick() end) My code, i dont know what to do and have been trying to fix this for hours. Please help me fix my code, this script is in the workspace under a model named "Npc" it has a humanoid and when it dies i want it to kick the player.
-- stuff lasttouch = nil collisionbox = Instance.new("Part") collisionbox.Parent = script.Parent collisionbox.Anchored = false collisionbox.Size = Vector3.new(10, 10, 10) collisonbox.Transparency = 1 collisionbox.CFrame = script.Parent.HumanoidRootPart.CFrame -- making da weld theweld = Instance.new("WeldConstraint") theweld.Parent = script.Parent.HumanoidRootPart theweld.Part0 = script.Parent.HumanoidRootPart theweld.Part1 = collisionbox theweld.Enabled = true -- event collisionbox.Touched:Connect(function(hit) if hit.Name == "HumanoidRootPart lasttouchplayer = game.Players[hit.Parent.Name] end end) script.Parent:WaitForChild("Humanoid") -- event number 2 script.Parent.Humanoid.Died:Connect(function() lasttouchplayer:Kick("You killed me :(") end)
I am assuming it is not being shot with a gun and that the player needs to be in close proximity in order to "kill" the npc.
Tell me if this works! :D