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 4 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.

01InRound.Changed:Connect(function()
02    if InRound.Value == true then
03        local RandomPlayer = game.Players:GetPlayers()[math.random(1,PlayerCount)]
04        RandomPlayer.Team = Killer
05        for _, player in pairs(game.Teams.Lobby:GetPlayers()) do
06            player.Team = Campers
07        for _, player in pairs(game.Players:GetChildren()) do
08            player:LoadCharacter()
09            end
10        end
11    else
12        for _, player in pairs(game.Players:GetChildren()) do
13            player.Team = Lobby
14            local char = player.character
15            char.HumanoidRootPart.CFrame = Spawn.CFrame
16        end
17    end
18end)

2 answers

Log in to vote
0
Answered by 4 years ago
1local player = game.Players.LocalPlayer
2local tool = game.ServerStorage.Tool --Reference your tool here
3local toolclone = tool:Clone() --Clones the tool
4toolclone.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 — 4y
0
You shouldn't give a tool from a local script. Only from a server script. LightningLIon58 49 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 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:

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

Way 2:

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

Way 3:

1--Here's an example of way 3
2local tool = nil --Replace nil with the path to your tool (e.g. ServerStorage.Sword)
3local clone = tool:Clone()
4local char = RandomPlayer.Character or RandomPlayer.CharacterAdded:Wait() --Seems like you already defined RandomPlayer so I used it.
5local humanoid = char:WaitForChild("Humanoid")
6humanoid:EquipTool(clone)
7--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