(Yes, believe me, I searched and nothing worked)
I have a script that works in studio but not in the real game. Here’s the script:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local ToolCount = 0
for i, v in pairs(player.Character:GetChildren()) do
if v.ClassName == "Tool" then
ToolCount += 1
end
end
for i, v in pairs(player.Backpack:GetChildren()) do
ToolCount += 1
end
if ToolCount < player.Character.InventorySlots.Value then
local Item = workspace["Flash Light"]:Clone()
script.Parent:Destroy()
Item.Parent = player.Backpack
else
if player.PlayerGui.ScreenGui.TooMany.TextTransparency == 0 then
local count = 0
player.PlayerGui.ScreenGui.TooMany.Visible = true
repeat
player.PlayerGui.ScreenGui.TooMany.TextTransparency += 0.01
count += 1
wait(0)
until count == 100
player.PlayerGui.ScreenGui.TooMany.Visible = false
player.PlayerGui.ScreenGui.TooMany.TextTransparency = 0
end
end
end)
The error is: Workspace.Crate.ProximityPrompt.Flash Light.Script:14: attempt to index nil with ‘Item’. Why does this happen?