How do I fix these tools?

So I have these two tools that for some reason won’t let me grab it twice and randomly gives it to other people.

Here are all the scripts:

Plate Of Steak Script:

local tool = game.Lighting["Raw Big Boi Steak"]
local klone = tool:clone()

script.Parent.ClickDetector.MouseClick:connect(function(plr)
     if klone.Parent ~= plr.Backpack then
         klone.Parent = plr.Backpack
     end
 end)

Plate Of Wings Script:

local tool = game.ServerStorage["Raw Chicken Wing"]
local klone = tool:clone()

script.Parent.ClickDetector.MouseClick:connect(function(plr)
     if klone.Parent ~= plr.Backpack then
         klone.Parent = plr.Backpack
     end
 end)

The Tools don’t have any scripts (Accept some that don’t matter like animation)

Why do you have tools under lighting?

2 Likes

You only defined the tool once and so it is trying to parent the same tool. Make it define the tool in the function

2 Likes

I don’t understand. Can you explain?

‘Klone’ is defined once. But this means that the 2nd time the function is activated, it will try to parent the exact same tool

1 Like

Move ‘local Klone’ into the function

script.Parent.ClickDetectore.MouseClick:Connect(function(plr)
    local klone = tool:Clone()
    -- rest of code
2 Likes

lemme see if that works, thank you.

1 Like

it didn’t work at all. Maybe make it a local script?

Because you’re checking if it is bigger than nil, It checks 1 time and since nothing is in you’re inventory but the 2 time it is already in you’re inventory and you’re checking if it is nil.

Try remove the if nil.

Did you move it into the function like I said? Because it should work if you did that…

1 Like

the script right now:

local tool = game.ServerStorage["Raw Chicken Wing"]

script.Parent.ClickDetector.MouseClick:connect(function(plr)
	local klone = tool:clone()
	if klone.Parent ~= plr.Backpack then
		klone.Parent = plr.Backpack
	end
end)

Yes, that is what I meant, does it work now?

1 Like

No, i tried it like that and it didnt work.

Are there any errors in the output?

1 Like

No, No errors appeared when i tested.

edit: Ima try putting it as a LocalScript

Maybe add print statements, to see which parts of the code runs successfully

1 Like

If the tools are in serverstorage, don’t use a local script, use a remote event

1 Like

one of them is in serverstorage the other was in lighting