-
What do you want to achieve?
The tool parameter is passed from the client to the server, and then the tool that is supposed to be removed from the player’s StarterGear & Backpack is removed. -
What is the issue?
The tool parameter is not being passed from the client to the server. Instead, it passes the player’s name for both the tool & the player. -
What solutions have you tried so far?
I’ve tried re-writing the script multiple times
Client-side Script:
local player = game.Players.LocalPlayer
local remote = game.ReplicatedStorage.DeleteItem
-- Listen for the button click event
button.MouseButton1Click:Connect(function(plr)
local backpack = player.Backpack
local starterGear = player.StarterGear
local toolName = script.Parent.Parent.name.Text -- How to retrieve the tool name
local tool = nil
script.Parent.Parent:Destroy() -- Destroy the GUI element
remote:FireServer(player, toolName)
print("Tool not found in backpack or starter gear")
end)
Server-side Script:
local deleteRemote = game.ReplicatedStorage.DeleteItem
deleteRemote.OnServerEvent:Connect(function(plr, tool)
print("remote connected server")
print(tool)
print(plr.Name)
local backpack = plr.Backpack
local starterGear = plr.StarterGear
for _, item in ipairs(backpack:GetChildren()) do
if item:IsA("Tool") and item.Name == tool then
item:Destroy() -- Remove the tool from the backpack
break -- No need to continue searching
end
end
for _, item in ipairs(starterGear:GetChildren()) do
if item:IsA("Tool") and item.Name == tool then
item:Destroy() -- Remove the tool from the StarterGear
break -- No need to continue searching
end
end
print(plr.Name .. " removed a " .. tool.Name)
end)
This is a screenshot of the output: