If you want this to work in the local script, and the server can see it, then add a RemoteFunction/RemoteEvent.
If you just want it serversided then type the following script:
local player = game:GetService("Players").PlayerAdded:Connect(function()
local itemName = "SledgeHammer"
if player.Backpack:FindFirstChild(itemName) and player.Backpack[itemName]:IsA("Tool") then
player.Backpack.SledgeHammer:Destroy()
end
end)
If this doesn't work try this:
local player = game:GetService("Players")
local backpack = player:WaitForChild("Backpack")
local character = player.Character or player.CharacterAdded:Wait()
local function Tools(container)
for _, item in pairs(container:GetChildren()) do
if item:IsA("Tool") and item.Name:match("SledgeHammer") then
item:Destroy()
end
end
end
Tools(backpack)
Tools(character)
Local scripts only works when it's a descendant of any following objects/services:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service
Note: Let me know if it works, as I haven't tested it out.
4 comments
local scripts don't work in workspace, it should be a server script
so any edit needed for that except for server script
yes, local scripts can't use LocalPlayer, you will need to change the way you include player
so how can indicate all players?