I would like to know how to do this script
COMMUNITY QUESTION
How do you script a NPC when killed gives you a tool?
1 answer
Inside the NPC add a server script not a local script and put your tool you want it to drop inside replicated storage then write this script.
local PlayerGivenTool = nil
function onTouched(hit)
if hit.Parent.ClassName == "Model" then
PlayerGivenTool = hit.Parent
end
end
script.Parent.Humanoid.Died:Connect(function()
if PlayerGivenTool ~= nil then
--Change Tool to your tool inside replicatedstorage
game.ReplicatedStorage.Tool:Clone().Parent = PlayerGivenTool
end
end)
script.Parent.HumanoidRootPart.Touched:Connect(onTouched)
script.Parent.Head.Touched:Connect(onTouched)
script.Parent.RightLowerArm.Touched:Connect(onTouched)
script.Parent.LeftLowerArm.Touched:Connect(onTouched)
script.Parent.RightLowerLeg.Touched:Connect(onTouched)
script.Parent.LeftLowerLeg.Touched:Connect(onTouched)
This discussion is preserved as it was. New answers, comments, and votes are closed.
