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

I have this script in my tool, but I want it to automatically hold the Tool. How?

Asked by 5 years ago
script.Parent.Handle.Touched:connect(function(hit) 
pcall(function() 
player = game.Players:getPlayerFromCharacter(hit.Parent) 
script.Parent:Clone().Parent = player.Backpack 
script.Parent:Remove() 
end) 
end)

How do I make it automatically hold the item when grabbed or taken off the ground?

1 answer

Log in to vote
0
Answered by 5 years ago

Hi ken,

You make the Player equip the tool by parenting the tool to the Character. What you're trying to do is quite simple and I just made a short script that accomplishes it. I would hope that you examine this script and learn from it, it's the best way to learn how to do what you're asking.

local part = script.Parent; -- The part that has the tool.

part.Touched:Connect(function(obj)
    local hum = obj.Parent:FindFirstChildOfClass("Humanoid"); -- To check if a player touched the part.

    if hum then -- Checks if it's a player that touched the part.
        local tool = script.Parent:WaitForChild("ToolToGive"):Clone(); -- Clones the tool.

        tool.Parent = obj.Parent; -- Parents it to the Character

        part:Destroy(); -- Destroys the part so nobody else can get the tool.
    end
end)

Well, hope I helped and have a fabulous day/night.

Thanks,

Best regards,

~~ KingLoneCat

Ad

Answer this question