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

Help, Npc kicks player after it dies?

Asked by 3 years ago

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.

0
you can't get LocalPlayer from a script BabanizPROcuk 49 — 3y
0
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 SnowyNomad 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
-- 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

0
Has your problem been fixed? boomthefist 6 — 3y
Ad

Answer this question