Script help for a roblox grocery store click detector broken

Hi! I have a grocery store and I can’t figure out why the script I have in server script service isn’t working. Expected behavior: When you click on an item it should put it in your backpack. `–Modder0Source
local data = require(game.ReplicatedStorage.Products)
local prods = game.ServerStorage.Products
local work = game.Workspace.Products

function getitemamount(name,obj)
local amount = 0
for i,v in pairs(obj:GetChildren()) do
if string.lower(name) == string.lower(v.Name) then
amount = amount + 1
end
end
return amount
end

for i,data2 in pairs(data) do
spawn(function ()
if prods:FindFirstChild(data2.ProductName) then
prods[data2.ProductName].CanBeDropped = false
if prods[data2.ProductName].Handle:FindFirstChild(‘EAN’) then
prods[data2.ProductName].Handle:FindFirstChild(‘EAN’).Value = i
else
local clone = script.EAN:Clone()
clone.Parent = prods[data2.ProductName].Handle
local clone = script.EAS_Active:Clone()
clone.Parent = prods[data2.ProductName].Handle
prods[data2.ProductName].Handle:FindFirstChild(‘EAN’).Value = i
end
end
end)
end

for i,v in pairs(work:GetChildren()) do
spawn(function()
if v:FindFirstChild(‘Click’) and prods:FindFirstChild(v.Name) then
v.Click.Transparency = 1
v.Click.ClickDetector.MouseClick:Connect(function(p)
if getitemamount(v.Name,p.Backpack) < 3 then
prods:FindFirstChild(v.Name):Clone().Parent = p.Backpack
end
end)
end
end)
end`

Couldn’t test if the script works but I fixed some problems that I’ve found.

local data = require(game.ReplicatedStorage.Products)
local prods = game.ServerStorage.Products
local work = game.Workspace.Products

function getitemamount(name, obj)
    local amount = 0
    for _, v in pairs(obj:GetChildren()) do
        if string.lower(name) == string.lower(v.Name) then
            amount = amount + 1
        end
    end
    return amount
end

for i, data2 in pairs(data) do
    spawn(function()
        if prods:FindFirstChild(data2.ProductName) then
            prods[data2.ProductName].CanBeDropped = false
            if prods[data2.ProductName].Handle:FindFirstChild('EAN') then
                prods[data2.ProductName].Handle:FindFirstChild('EAN').Value = i
            else
                local clone = script.EAN:Clone()
                clone.Parent = prods[data2.ProductName].Handle
                local clone2 = script.EAS_Active:Clone()
                clone2.Parent = prods[data2.ProductName].Handle
                prods[data2.ProductName].Handle:FindFirstChild('EAN').Value = i
            end
        end
    end)
end

for _, v in pairs(work:GetChildren()) do
    spawn(function()
        if v:FindFirstChild('Click') and prods:FindFirstChild(v.Name) then
            v.Click.Transparency = 1
            v.Click.ClickDetector.MouseClick:Connect(function(p)
                if getitemamount(v.Name, p.Backpack) < 3 then
                    local itemClone = prods:FindFirstChild(v.Name):Clone()
                    itemClone.Parent = p.Backpack
                end
            end)
        end
    end)
end

1 Like

I tried it but it didn’t work. I can try to send a copy of the game

Just Make a click detector and make a script. the script shoiuld look like this:`

local clickDetector = script.Parent – Assuming The Click Detector Is The Parent Of The Script

local function onActivated()
local player = game.Players:GetPlayerFromCharacter(clickDetector.Parent)
if player then
local tool = player.Backpack:FindFirstChild(“YourToolName”)
if tool then
tool.Parent = player.Character
end
end
end

clickDetector.MouseClick:Connect(onActivated)

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