Weird Tool Problem

Hi Dev Forum Community. I’ve encountered a big issue with tools in my game and I have no idea how to fix it. The problem is that the person holding the tool can see all of the parts of it (In this case it being the ice cream parts and cone/milkshake parts and glass/the full pastry) and the other person only sees one part of it or no parts of it. Here are pictures below:

POV of the person holding the item: (In this case ice cream)

cone

POV of the other persons view of the item: (In this case ice cream, but for things like pastries it shows nothing)

The tool is coming from a GUI that gives you a tool from replicated storage. Additionally, for whatever reason, my hand to GUI does not work for any of the food items, but it works for other items. I’m confused and don’t know what to do. If you need to know anything in order to help me, please ask. Thank you!

1 Like

Could you provide the script for the handto GUI?

1 Like

Are you talking about the GUI that the baristas use to give the item to players or the GUI that you get the item from?

1 Like

Both of them, so we’re able to troubleshoot this problem!

Here’s the script for the GUI button that the baristas click to get the tool:


script.Parent.MouseButton1Click:Connect(function()
	local P = game.Players.LocalPlayer
	local character = P.Character
	local backpack = P.Backpack

	-- Check if the "Cone" item exists in the backpack or on the character
	if backpack:FindFirstChild("Cone") then
		backpack.Cone:Destroy()
	elseif character and character:FindFirstChild("Cone") then
		character.Cone:Destroy()
	end

	-- Clone and place the new ice cream item into the backpack
	local Copied = H:Clone()
	Copied.Parent = backpack
end)

It’s just made so if they have a cone in their backpack or they have it equipped it destroys it. Also, I don’t think the hand to GUI has anything to do with it because it works for every other tool just not the food tools that I’ve recently made that they get from the GUIs.

1 Like

You should not be directly modifying the Player’s backpack from a LocalScript, as it can cause some tools to error out. Instead, replace the buttons in the LocalScript so that they fire a RemoteEvent:

local remoteEvent = game.ReplicatedStorage:WaitForChild(“ItemEvent”)

script.Parent.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(“Cone”) -- Sends the argument of which tool the Player is trying to get through the RemoteEvent.
end)

And on a ServerScript:

local rs = game:GetService(“ReplicatedStorage”)
local remoteEvent = rs:WaitForChild(“ItemEvent”)

remoteEvent:OnServerEvent:Connect(function(Player, toolName)
       local isToolGiven = Player.Character:FindFirstChild(toolName) or Player.Backpack:FindFirstChild(toolName) -- Checking if tool is already given.
          if not isToolGiven then
            local tooltoGive = rs:FindFirstChild(toolName)
            local toolClone = tooltoGive:Clone()
            toolClone.Parent = Player.Backpack
        end
end)

If you want to make it such that the Script swaps tools, do this for the ServerScript:

local rs = game:GetService(“ReplicatedStorage”)
local remoteEvent = rs:WaitForChild(“ItemEvent”)

remoteEvent:OnServerEvent:Connect(function(Player, toolName)
       local isToolGiveninCharacter = Player.Character:FindFirstChild(toolName) 
       local isToolGiveninBackpack = Player.Backpack:FindFirstChild(toolname)
         
         if isToolGiveninCharacter then
           isToolGiveninCharacter:Destroy()
         end

         if isToolGiveninBackpack then
           isToolGiveninBackpack:Destroy()
         end

         local tooltoGive = rs:FindFirstChild(“ToolNameHere”) -- Edit to the name of the tool you want to give.
         local toolClone = tooltoGive:Clone()
         toolClone.Parent = Player.Backpack
end)

Thanks! I’ll try it right now. Also, is that configured so it will destroy the tool from their inventory?

Were you doing that because you wanted to prevent Players from getting duplicate tools?

If you were, I have included a isToolGiven variable in the ServerScript. If the server finds the tool with the specified name in the Player, it will not give the Player the tool.

The reason it destroys the cone is that the UI only opens if you have a cone, so I want it to destroy the cone as well.

That seems like a strange way to open the UI, is this intentional, or is this GUI for a separate purpose?

But if you wish to destroy the Player’s cone as well, then this should be the ServerScript:

local rs = game:GetService(“ReplicatedStorage”)
local remoteEvent = rs:WaitForChild(“ItemEvent”)

remoteEvent:OnServerEvent:Connect(function(Player, toolName)
       local isToolGiveninCharacter = Player.Character:FindFirstChild(toolName) 
       local isToolGiveninBackpack = Player.Backpack:FindFirstChild(toolname)
         
         if isToolGiveninCharacter then
           isToolGiveninCharacter:Destroy()
         end

         if isToolGiveninBackpack then
           isToolGiveninBackpack:Destroy()
         end

         local tooltoGive = rs:FindFirstChild(“ToolNameHere”)
         local toolClone = tooltoGive:Clone()
         toolClone.Parent = Player.Backpack
end)

The baristas need a cone in order for the proximity prompt to work and open the GUI, then they select their flavor in the GUI.

1 Like

Well, if that’s the case, you will need to replace this line:

With the tool which you would like to give:

local tooltoGive = rs:FindFirstChild(“ToolNameHere”)

Thanks so much for your help! It worked for the first tool and now I have to do it for about 34 others… Either way, thank you so much and I’ll update you if something doesn’t work.

Of course. Do mark this reply as the solution of the topic, so others are able to know how to fix the issue!

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