Simple Bug Issue

Hey, so I’ve taken a several month break from scripting and have already forgotten so much. Could someone please help me with this simple issue? I’m trying to make a block placement system that resembles MineCraft. Basically this is a lucky block, that when opened, should drop an item on the ground and disappear. The item however, does not appear. The block does get destroyed though… Also, the positional print statements do not run. Any ideas?

Note: The loot is all tools. (Yes they all have a “Handle”)

local replicatedStorage = game:GetService("ReplicatedStorage")
local loot = replicatedStorage:WaitForChild("Loot") -- // Folder containing the loot options
local proxPrompt = script.Parent.ProximityPrompt
local block = script.Parent

local sword = loot.Sword
local armor = loot.Armor
local wood = loot.Wood

local items = {sword, armor, wood} -- // table containg the loot items



proxPrompt.Triggered:Connect(function(player) -- // when player breaks the lucky block, run this code
	local selectedItem = items[math.random(1, #items)] -- // select a random item

	local newItem = selectedItem:Clone() -- // clone the item

	if newItem.Name == "sword" then -- // check if the item is a sword
		newItem.Parent = workspace
		newItem.Position = block.Position

		print(newItem.Position) -- // debugging print statements which aren't running
		print(block.Position) -- // debugging print statements which aren't running
	elseif newItem.Name == "armor" then -- // check if the item is armor
		newItem.Parent = workspace
		newItem.Position = block.Position

		print(newItem.Position)
		print(block.Position)
	elseif newItem.Name == "wood" then -- // check if the item is wood
		newItem.Parent = workspace
		newItem.Position = block.Position

		print(newItem.Position)
		print(block.Position)
	end
	block:Destroy() -- // destroy the lucky block
end)

Any help is much appreciated!

I think the problem relies on the “newItem.Name == “sword” it’s lowercase however, when you named the sword, armor, wood. They’re capitalized, what I mean is this “loot.Sword” it’s capitalize. So, it doesn’t find the child named “sword” so just capitalize the s.

If newItem.Name == “Sword” then
— code goes here
end

Then you’ll do this for every single one of your items since their first letter is capitalized, so sorry if this is confusing. Here’s another example

You see how loot.Sword, sword is capitalized? When you tried to find their name, you just did this “sword”, sword is lowercased so it couldn’t find the child of your selected items.

1 Like

Thank you, that was the issue! I can’t believe I overlooked that…

1 Like

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