local Spawner = Vector3.new(157.324, 0.974, 26.163) local Clicker = script.Parent local ObjectSpawn = script.Parent.Parent.Spawn local debounce = false Clicker.MouseClick:Connect(function(player) if not debounce then debounce = true local Backpack = player:FindFirstChild("Backpack") if Backpack ~= nil then print "Check" local Obj = Backpack:GetChildren() if Obj == ("Bowl") then local Object = game.ReplicatedStorage:findFirstChild("Bowl") print "Bowl" end if Obj == ("Classic") then local Object = game.ReplicatedStorage:findFirstChild("Classic") print "Classic" else local Object = game.ReplicatedStorage:findFirstChild("Cardboard") print "Cardboard" script.Parent.Parent.BrickColor = BrickColor.new("Persimmon") local CloneObject = Object:Clone() CloneObject.Parent = game.Workspace CloneObject:MoveTo(Spawner) wait (12) script.Parent.Parent.BrickColor = BrickColor.new("Shamrock") debounce = false end end end end)
This script is meant to check if a player has an item in their inventory, and if so, spawn it. For some reason though, it always spawns cardboard. It is printing check, so I have found the player's backpack, but when I put either "Bowl" or "Classic" in the starter pack it still spawns cardboard. Also, nothing else is being printed. Why?
You only spawn Cardboard because you're comparing Obj (which is a table) to a string, which will be false. On the else statement, you finally set Object to the Cardboard, so it will always spawn the cardboard. You can also use a for loop to reduce the number conditionals that you have to write.
local Spawner = Vector3.new(157.324, 0.974, 26.163) local Clicker = script.Parent local ObjectSpawn = script.Parent.Parent.Spawn local debounce = false Clicker.MouseClick:Connect(function(player) if not debounce then debounce = true local Backpack = player:FindFirstChild("Backpack") if Backpack ~= nil then print "Check" --I assume you want to spawn one random item from the player's inventory. local Item= {} local Obj = Backpack:GetChildren() for _,v in pairs(Obj) do print(v.Name) table.insert(item, v) end --If the player has the item then clone a random one to workspace. if #Item ~= 0 then local Object = game.ReplicatedStorage:FindFirstChild(Item[math.random(1,#Item)].Name) if Object then Clone = Object:Clone() Clone.Parent = workspace Clone:MoveTo(Spawner) end end script.Parent.Parent.BrickColor = BrickColor.new("Persimmon") wait(12) script.Parent.Parent.BrickColor = BrickColor.new("Shamrock") debounce = false end end end)