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!