Parameter is not being passed correctly

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

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

  3. What solutions have you tried so far?
    I’ve tried re-writing the script multiple times :confused:

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:

The first parameter in OnServerEvent is automatically the player / client the remote was fired from which means you don’t have to pass it in the FireServer method.

So just remove the player argument from FireServer (remote:FireServer(toolName))

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.