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

How do you script a NPC when killed gives you a tool? [closed]

Asked by 5 years ago

I would like to know how to do this script

Closed as Not Constructive by cmgtotalyawesome, pidgey, Igoralexeymarengobr, and OnaKat

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago

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)
Ad