Hi. I have a minor problem with spawning the item in the right place. If you could help me. robloxapp-20220702-1716187.wmv (3.3 MB)
here is a video of what I mean. the green cube represents (for now) an item and the gray cuboid as well. if If I open the box (ProximityPrompt), all objects in one folder should be cloned and placed at the position of the box. However, that is not happening. the items instead appear on another one (which opened before) I don’t know what to do with it. Here is my script.
local tile = script:GetChildren()
local Insane = game.ServerStorage.itemy.insane:GetChildren()
local Legendary = game.ServerStorage.itemy.legendary:GetChildren()
local Epic = game.ServerStorage.itemy.epic:GetChildren()
local Rare = game.ServerStorage.itemy.rare:GetChildren()
local Uncomnom = game.ServerStorage.itemy.uncomnom:GetChildren()
local Comnom = game.ServerStorage.itemy.comnom:GetChildren()
-----------
local insane = {}
local legendary = {}
local epic = {}
local rare = {}
local uncomnom = {}
local comnom = {}
-----------
for i = 1, #Insane do
table.insert(insane, Insane[i])
end
for i = 1, #Legendary do
table.insert(legendary, Legendary[i])
end
for i = 1, #Epic do
table.insert(epic, Epic[i])
end
for i = 1, #Rare do
table.insert(rare, Rare[i])
end
for i = 1, #Uncomnom do
table.insert(uncomnom, Uncomnom[i])
end
for i = 1, #Comnom do
table.insert(comnom, Comnom[i])
end
-----------------------------------------------------------------------------
for i = 1, #tile do
local POSITION = tile[i].Position
tile[i].ProximityPrompt.Triggered:Connect(function()
local random = 100 --math.random(1,100)
print(random)
local new
if random == 100 then
----------------------- insane
print("insane")
local Picked = math.random(1, #Insane) print("náhoda z Insane")
new = insane[Picked]:GetChildren() print("nové itemy (:GetChildren)")
elseif random >= 94 then
----------------------- legendary
print("legendary")
local Picked2 = math.random(1, #Legendary)
elseif random >= 84 then
----------------------- epic
print("epic")
local Picked3 = math.random(1, #Epic)
elseif random >= 69 then
----------------------- rare
print("rare")
local Picked4 = math.random(1, #Rare)
elseif random >= 44 then
----------------------- uncomnom
print("uncomnom")
local Picked5 = math.random(1, #Uncomnom)
else
----------------------- comnom
print("comnom")
local Picked6 = math.random(1, #Comnom)
end
-------------------------------------------------------------------------------------------
for i = 1, #new do
local position = tile[i].Position
new[i]:Clone().Parent = game.Workspace.HRA.Items
new[i].Position = POSITION print(new[i].Position) --ERROR HERE
end
tile[i].Transparency = 0.8
--tile[i]:Destroy()
end)
end
This is not a problem, I calculated it in percentages.
I would rather be interested in why the items are not placed correctly. because idk.
So far I have set it to always be insane (for testing)
I tried that, it does the same thing.
I even put local POSITION = tile[i].Position in that loop and also nothing.
for i = 1, #new do
local POSITION = tile[i].Position
--local position = tile[i].Position
new[i]:Clone().Parent = game.Workspace.HRA.Items
new[i].Position = POSITION print(new[i].Position) --ERROR HERE
end
tile[i].Transparency = 0.8
--tile[i]:Destroy()
end)
I’m not entirely sure if I’m understanding your script correctly, but it’s obvious from the video that the problem is happening because it’s not retrieving the tile correctly because of the ‘i’ variable.
Here’s what I would try:
for i = 1, #tile do
local TILE = tile[i]
TILE.ProximityPrompt.Triggered:Connect(function()
local random = 100 --math.random(1,100)
local new
if random == 100 then
----------------------- insane
print("insane")
local Picked = math.random(1, #Insane) print("náhoda z Insane")
new = insane[Picked]:GetChildren() print("nové itemy (:GetChildren)")
end
-------------------------------------------------------------------------------------------
for n = 1, #new do
new[n]:Clone().Parent = game.Workspace.HRA.Items
new[n].Position = TILE.Position
end
TILE.Transparency = 0.8
--tile[i]:Destroy()
end)
end
In the above script, I made the tile its own variable, and change the ‘i’ in the nested for loop at the bottom to an ‘n’.
well i tried that it still does the same thing. But if you don’t understand the script, I’ll tell you what it does: in short. it’s hard to say whether the translator also messed it up.
The folder from which the draw will be drawn is drawn, then what is to be dropped is drawn from the draw, and then the content from the draw is to be spawned. I don’t know if there is chaos in it. but this is what the folder looks like:
I also discovered that if I put more items there, it does something else. (I added the drop2 folder there, which was not there before) robloxapp-20220702-1936205.wmv (4.7 MB)
maybe it would be best to start over if I don’t come up with a solution.
Yeah, I was kind of trying to avoid rewriting a large portion of your code. But I feel like that’s probably the best solution. I feel like you have a lot of unnecessary tables and loops. Something simple like this might be better:
local tiles = script:GetChildren()
local Insane = game.ServerStorage.itemy.insane:GetChildren()
-- All your other rarity variables here
for _, TILE in pairs(tiles) do
TILE.ProximityPrompt.Triggered:Connect(function()
local random = 100 --math.random(1,100)
local new
if random == 100 then
----------------------- insane
local picked = math.random(1, #Insane)
new = Insane[picked]:GetChildren()
-- All of your other elseif statements here
end
new:Clone().Parent = game.Workspace.HRA.Items
new.Position = TILE.Position
end)
end
You don’t need to make new tables to store the Instance’s children in because GetChildren returns its own table with the children of your Instance inside of it.