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

why is the tool not being given to the player?

Asked by 2 years ago

I'm trying to make it so all tools the player has are taken from the player and they are given the clone of the tool I want to give them, except it isn't giving them the tool.

local tool = game.ServerStorage.Tools["Spool"]

script.Parent.Triggered:Connect(function(player)

    local t = tool:Clone()
    local hum = player.Character:FindFirstChild("Humanoid")
    player:WaitForChild("Backpack"):ClearAllChildren()
    wait(0.5)
    hum:EquipTool(t)

end)

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

Its pretty easy, you've just forgot to parent the tool/weapon, I've also decided to put the code where all the Inventory you've have disappears before you get the weapon, this Is so the code doesn't get confused and deletes It, Hopes It helps

EDIT: I forgot to add that I've expect this Is a server script Inside of a Promp

local tool = game.ServerStorage.Tools["ClassicSword"] --Expects the tool Is Inside of a folder In ServerStorage

script.Parent.Triggered:Connect(function(player)

    player:WaitForChild("Backpack"):ClearAllChildren()  --Do this command before the user gets the weapon
    local t = tool:Clone()
    local Char = player.Character
    local hum = Char:FindFirstChild("Humanoid")
    t.Parent = Char --You've forget to parent the tool to the players Inventory
    wait(0.5)
    hum:EquipTool(t)

end)
Ad

Answer this question