Item not received in inventory when clicked

Recently made a script in which you click the item within the store such as candy and you will be given it as a tool. It has worked in the testing game and a few other places but moment I have attempted to place it within my main game it suddenly breaks? The game itself has no scripts and there is no error within the script, instead of placing a tool within your inventory it instead duplicates the item on the store shelves.

Script

1 Like

Can you show me an error inside the output?

That is the thing, there is no error inside the output itself, it is kinda baffling.

Why not put the tools in server storage and do something like this?

local toolsArray = {"Chocolate Pocky"}
local Storage = game:GetService("ServerStorage")

local MeshPart = script.Parent
local clickDetector = MeshPart:WaitForChild("ClickDetector")

local function onClicked(player)
	if player and player.Character then
		local Backpack = player:WaitForChild("Backpack")
		for i = 1, #toolsArray do
			local Tool = Storage:FindFirstChild(toolsArray[i])
			if Tool then
				Tool:clone().Parent = Backpack
				Tool:Destroy()
			end
		end
	end
end
clickDetector.MouseClick:Connect(onClicked)

If you want to be able to pick up the item multiple times them remove Tool:Destroy() and if you want the mesh part to be removed then replace Tool:Destroy() with MeshPart:Destroy()

Slight issue with that is, the original idea is the following; Click the item which then it turns into a Tool, as originally we don’t want tons of tools cluttering the storage and this does work issue is it isn’t working on the main game but works in others.

As your version does mean we’d have to create the tool before hand and place it within serverstorage it defeats the purpose of this

Are you destroying the script that moves the tool

handle.Script:Destroy()

before it moves the tool?

newTool.Parent = game.Workspace:FindFirstChild(player.Name)

Suggested edit

newTool.Parent = player.Character

Just switch those two lines around and you should be fine.

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