Hi, so this code won’t work when I equip a tool, and use the proximity prompt, it doesn’t do the thing it’s supposed to do. I think there’s a problem with the “local ToolEquipped = Player.Character and Player.Character:FindFirstChildOfClass(“Tool”)” however I’m not sure, as you already saw the script is running in LocalScript, and the scripts parent is a Proximity Prompt.
script.Parent.Triggered:Connect(function()
local Player = game.Players.LocalPlayer
local ToolEquipped = Player.Character and Player.Character:FindFirstChildOfClass("Tool")
if ToolEquipped then
local toolName = ToolEquipped.Name
if toolName == "Cake Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cake Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Cookie Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cookie Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Cupcake Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cupcake Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Mochi Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Mochi Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Muffin Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Muffin Dough"]:Clone()
Clone.Parent = Player.Backpack
end
end
end)
script.Parent.Triggered:Connect(function(Player)
local ToolEquipped = Player.Character and Player.Character:FindFirstChildOfClass("Tool")
if ToolEquipped then
local toolName = ToolEquipped.Name
if toolName == "Cake Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cake Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Cookie Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cookie Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Cupcake Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Cupcake Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Mochi Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Mochi Dough"]:Clone()
Clone.Parent = Player.Backpack
elseif toolName == "Muffin Dough" then
ToolEquipped:Destroy()
local Clone = game.ServerStorage["Rolled Muffin Dough"]:Clone()
Clone.Parent = Player.Backpack
end
end
end)```
I added the script into a Serverside one, not a client one.
If you think that part might be the issue, then try using the debugger and Watch window to inspect variables and control flow as the program executes one line at a time.
Okay, let’s try to debug from the name of the ToolEquipped variable.
Can you temporarily remove the code below the first print() function, and just detect if a Player is holding a tool, and try printing the results. Something like:
script.Parent.Triggered:Connect(function(Player)
local ToolEquipped = Player.Character:FindFirstChildOfClass(“Tool”)
print(ToolEquipped.Name)
end)