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.
COMMUNITY QUESTION
Help, Npc kicks player after it dies?
1 answer
-- 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
1 comment
0
Has your problem been fixed?
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
you can't get LocalPlayer from a script
ive tried revising my code local humanoid = script.Parent:WaitForChild('Humanoid') local player = game.Players.LocalPlayer humanoid.Died:Connect(function() player:Kick() end) and its in a local script with this one, but nothing happens after humanoid death