Anyone knows how or what to do to make every player get a tool after they pick up, just like 1 tool per player after they pick up that tool? my issue yesterday the other player can’t get a tool while the other one who got the tool first will be the only one who got the tool.I hope yall can help me.
(Player X in this case will be the local player, so basically the individual who does the action)
(This also assumes that you put a copy of the tool into some sort of storage that the server has access to)
Assuming you want to have a static object that always gives a tool when selected, instead of “disappearing” after someone picks up the tool, you should probably just make the object a model that you can click on.
Once you click on it, the server needs to register that you clicked on the model, so have a remote event tell the server that this model was clicked by player X.
This event should then duplicate your tool and put it into the player’s backpack.
Then, that should be it.
local Players = game:GetService("Players")
local WorkSpace = workspace
WorkSpace.ChildRemoved:Connect(function(Child)
local Parent = Child.Parent
if Parent then
if Child:IsA("Tool") then
if Parent:IsA("Model") then
local Player = Players:GetPlayerFromCharacter(Parent)
if Player then
for _, OtherPlayer in ipairs(Players:GetPlayers()) do
if OtherPlayer ~= Player then
local Backpack = OtherPlayer.Backpack
local ToolClone = Child:Clone()
ToolClone.Parent = Backpack
end
end
end
end
end
end
end)
Here you go, I just tested this with a LinkedSword and it works. Here’s a similar version which prevents duplicate tools from being awarded.
local Players = game:GetService("Players")
local WorkSpace = workspace
WorkSpace.ChildRemoved:Connect(function(Child)
local Parent = Child.Parent
if Parent then
if Child:IsA("Tool") then
if Parent:IsA("Model") then
local Player = Players:GetPlayerFromCharacter(Parent)
if Player then
for _, OtherPlayer in ipairs(Players:GetPlayers()) do
if OtherPlayer ~= Player then
local OtherCharacter = OtherPlayer.Character
local Backpack = OtherPlayer.Backpack
local CharacterTool = OtherCharacter:FindFirstChild(Child.Name)
local BackpackTool = OtherCharacter:FindFirstChild(Child.Name)
if (not CharacterTool) and (not Backpack) then
local ToolClone = Child:Clone()
ToolClone.Parent = Backpack
end
end
end
end
end
end
end
end)
Here’s a slightly different approach where you click on a “ClickDetector” instance and are awarded the tool (providing you don’t already possess the tool).
local server = game:GetService("ServerStorage")
local tool = server.ClassicSword --Replace with name of tool.
local clickDetector = script.Parent
clickDetector.MouseClick:Connect(function(player)
local character = player.Character
local backpack = player.Backpack
local characterTool = character:FindFirstChild(tool.Name)
local backpackTool = backpack:FindFirstChild(tool.Name)
if characterTool or backpackTool then
return
end
local toolClone = tool:Clone()
toolClone.Parent = backpack
end)
Here’s the model file for this implementation.
repro.rbxm (9.4 KB)
The part which contains the “ClickDetector” instance can be given the appearance of the tool to be awarded (as you can see in the provided model file) without it being a tool itself. When this “ClickDetector” instance is clicked the real tool (which is safely kept in storage, in this case the “ServerStorage” folder) can be cloned into the backpack of the player that clicked the “ClickDetector” instance.