Trying to give tool but script cant find it

Hiya devs I am making a thing where a player can order food and then another player serves it, however the issue I am getting is that the script can not find the tool

script:

script.Parent.ServeButton.MouseButton1Click:Connect(function()
	if script.Parent.Premium.Text == "true" then
		local foodtools =  game.ReplicatedStorage.IFE.PremiumFoodItems[script.Parent.Main.Text.." | "..script.Parent.Drink.Text.." | ".. script.Parent.Dessert.Text]:Clone()
		foodtools.Parent = game.Players:WaitForChild(script.Parent.PlrName.Text).Backpack
		
	end
end)

Output:

Explorer
image

1.I Suggest doing this from a server script [using a remote event].
2.Have at top of your script variables and services to make your lines shorter and more efficient.

I’ll now fix your code.

Try this:

--client
--//Services
local Players= game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")

--//Variables
local Remote = Replicated:WaitForChild("GiveTool")
local Button = script.Parent

--//Functions
local function GiveTool()
	if script.Parent.Premium.Text == "true" then
		Remote:FireServer(script.Parent.PlrName.Text)
	end
end


--//Logic
Button.MouseButton1Click:Connect(GiveTool)
---Server
--//Services
local Players= game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")

--//Variables
local Remote = Replicated:FindFirstChild("GiveTool")

--//Logic
Remote.OnServerEvent:Connect(function(Player,Target)
	if not Players:FindFirstChild(Target) then return end
	local Tool = Replicated:FindFirstChild("YOUR_TOOL"):Clone()
	Tool.Parent = Players:FindFirstChild(Target).Backpack
end)

Notice: you might need to modify the scripts a bit.

I am now getting
“attempt to index nil with ‘Clone’”
I believe its due to me having to find the tool by doing

:FindFirstChild(script.Parent.Main.Text.." | "..script.Parent.Drink.Text.." | ".. script.Parent.Dessert.Text)

However, this is the only way unless writing over 350 lines more.

The script is trying to find “Braised Beef Cheek | Fanta | Cookie Dough” but the tool’s name is “Braised Beef Cheek | Cookie Dough | Fanta”. They have different names.

I just get an error message and nothing else now.

what does the error message say

Script ‘ServerScriptService.Script’, Line 127

That’s where the error occurs at. We need the error message(the red text).

“attempt to index nil with clone” , means that what you are trying to clone is not available or doesn’t exist

It’s because the name of the tool in picture 2 is not the same as the name in the error of the script in picture 1.

I dont know what I did but I managed to make it work somehow.

1 Like

Alright, since it worked, you may close the topic.