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

How to make weapon drop script work?

Asked by
TrollD3 105
9 years ago

I want to this script to be able to let players drop their weapons on the floor when they die. I also Want it to say v to pick up weapon above that weapon when it was dropped.

This is the script I have so far.

Tool = script.Parent
Char = Tool.Parent.Parent.Character

function onDeath()

if Tool.Parent == Char then
Tool.Parent = game.Workspace
end
end

Char.Humanoid.Died:connect(onDeath)
0
is it in a LocalScript or script? woodengop 1134 — 9y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Instead of trying to do this from the tool's perspective.. why not just put a script in workspace that makes it so whenever the character dies they drop their tool?

I'm not going to help with the press 'v' to pickup part because that would be non constructive on your part if I just did it for you.

--Function to drop tools
function dropTools(char)
    for i,v in pairs(char:GetChildren()) do
        if v:IsA('Tool') then
            v.Parent = workspace
        end
    end
end

--Player joins
game.Players.PlayerAdded:connect(function(plr)
    --Character spawns
    plr.CharacterAdded:connect(function(char)
        --Connect died event
        local hum = char:WaitForChild('Humanoid')
        hum.Died:connect(function()
            dropTools(char)
        end)
    end)
end)
Ad

Answer this question