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

How to put a tool into a player's inventory?

Asked by 3 years ago

Hi, beginner dev here. I am trying to make a script that should sort players into teams, place a tool into one team's inventory, and teleport the players to the map and lobby. The script works perfectly fine, except it won't put the tool into the player's inventory. There are no errors in the script or in output. I have tried dozens (not an exaggeration) of variations of the script but none of them work. I really need somebody to work with me here. Below is part of the script without any of the code that gives the tool to the team. I just need to know what to add to the script to transfer the tool, or if I need to change any other things to make it work.

InRound.Changed:Connect(function()
    if InRound.Value == true then
        local RandomPlayer = game.Players:GetPlayers()[math.random(1,PlayerCount)]
        RandomPlayer.Team = Killer
        for _, player in pairs(game.Teams.Lobby:GetPlayers()) do
            player.Team = Campers
        for _, player in pairs(game.Players:GetChildren()) do
            player:LoadCharacter()
            end
        end
    else
        for _, player in pairs(game.Players:GetChildren()) do
            player.Team = Lobby
            local char = player.character
            char.HumanoidRootPart.CFrame = Spawn.CFrame
        end
    end
end)

2 answers

Log in to vote
0
Answered by 3 years ago
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Tool --Reference your tool here
local toolclone = tool:Clone() --Clones the tool
toolclone.Parent = player.Backpack

I hope this helps!

0
This did not work for me. Also, can I replace 'player' in your script with 'RandomPlayer' in my script without any issues? If not, that may be the issue. SlightSalty 0 — 3y
0
You shouldn't give a tool from a local script. Only from a server script. LightningLIon58 49 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Seems like you have some player objects. Clone the tool and then: You have 3 options 1. Parent the tool to the Player.Backpack. 2. Parent the tool to the character (But you can do that only with 1 tool). 3. Get the humanoid and do Humanoid:EquipTool(toolObject). Way 1:

--Here's an example of way 1
local tool = nil --Replace nil with the path to your tool (e.g. ServerStorage.Sword)
local clone = tool:Clone()
clone.Parent = RandomPlayer --Seems like you already defined RandomPlayer so I used it.

Way 2:

--Here's an example of way 2
local tool = nil --Replace nil with the path to your tool (e.g. ServerStorage.Sword)
local clone = tool:Clone()
clone.Parent = (RandomPlayer.Character or RandomPlayer.CharacterAdded:Wait()) --Seems like you already defined RandomPlayer so I used it.
--If you use this way, you can parent only one tool.

Way 3:

--Here's an example of way 3
local tool = nil --Replace nil with the path to your tool (e.g. ServerStorage.Sword)
local clone = tool:Clone()
local char = RandomPlayer.Character or RandomPlayer.CharacterAdded:Wait() --Seems like you already defined RandomPlayer so I used it.
local humanoid = char:WaitForChild("Humanoid")
humanoid:EquipTool(clone)
--If you use this way, you can parent only one tool.

Note: None of these ways work with a local script. Use them in a local script since everyone should be aware of the tool being given to the player.

Answer this question