I just need the player to unequip a tool once a certain condition is met, i have everything done just need the function itself, couldn't find anything regarding that on the developer wiki.
✓ ANSWER ACCEPTED
How do i make the player unequip a tool through a script?
2 answers
✓ Accepted answer
you can use the humanoid:UnequipTools() function, demonstrated in the code below:
local Players = game:GetService("Players") -- gets the player service
local ContextActionService = game:GetService("ContextActionService") -- gets the cas service
local localPlayer = Players.LocalPlayer -- gets the local player
ContextActionService:BindAction("unequipTools", -- binds action to a function
function(_, userInputState)
if userInputState == Enum.UserInputState.Begin then
if localPlayer.Character then -- checks if the player has a character
local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid") -- checks if the player has a humanoid
if humanoid then -- checks if the player has a humanoid
humanoid:UnequipTools() -- unequips any equipped tool
end
end
end
end,
false,
Enum.KeyCode.U -- sets the keybind, in this example U, when a player presses the U key, any equipped tool will be unequipped.
)
- avenze
plr = game.Players.LocalPlayer
backpack = plr.Backpack -- player's backpack
tooleq = plr.Character:FindFirstChild("Tool")
tooluneq = backpack:FindFirstChild("Tool")
if tooluneq then return end
if tooleq then
tooleq.Parent = backpack
end
--im bad at english btw
just change da parent of da tool, when it's equip it will move to character and when it's unequip it will move to player's backpack
This discussion is preserved as it was. New answers, comments, and votes are closed.
