So you step on a part then you get the tool "Jar" added to your inventory. The limit of jars supposed to be 5 and stop giving you jars when that happens. So I create a table by getting the humanoids children named "Jar". The table is instantly at 27 when I step on the part so that is what my problem definitely is, just I do not know how to fix it. If any idea's, comment and if you provide a solution that works I will accept your answer and add to your reputation.
local object = script.Parent local debounce = false function givePlayerJar(hit) if hit.Parent:FindFirstChild("Humanoid")then if debounce == false then debounce = true local jarCheck = hit.Parent:GetChildren("Jar") local jarNum = table.getn(jarCheck) print(jarNum) if jarNum ~= 6 then local cloneJar = game.ReplicatedStorage.Jar:Clone() cloneJar.Parent = hit.Parent wait(1) debounce = false end end end end object.Touched:Connect(givePlayerJar)
its because this line gets all children of the player, all parts, animation, humanoid etc
local jarCheck = hit.Parent:GetChildren("Jar")
you have to check if the what getchildren returns really is jar because it ignores ("jar")
but you might need to do something else than adding to the varible as i do here
local object = script.Parent local jar = 0 local debounce = false function givePlayerJar(hit) if hit.Parent:FindFirstChild("Humanoid")then if debounce == false then debounce = true local jarCheck = hit.Parent:GetChildren("Jar") for i = 1, #jarCheck do print(jarCheck[i]) if jarCheck[i].Name == "Jar" then jar = jar + 1 end end if jar <= 6 then local cloneJar = game.ReplicatedStorage.Jar:Clone() cloneJar.Parent = hit.Parent wait(1) debounce = false end end end end object.Touched:Connect(givePlayerJar)