I made a button that spawns a block "SpawnRedBlock" the spawned block should then be put in another block with the same color "RecycleBinRed". It will make the SpawnRedBlock to fall throught the "RedRecycleBin" (and the ground at the moment)
I also done a green and blue button and blocks that works the same way and you cant put the wrong color in the wrong "Bin"
The problem I have is if I spawn more then one block of the same color and putt the second in the bin. Then the first block will fall through the ground insted of the one colliding with the RecycleBin. The "SpawnBlock" will continue to do this in the order they were spawned
I want the last block that the charcter used to trigger the code.
But I am new to programing and lua so if anyone would help me it would be nice to also explain why you used to code as you did.
the script I put in the button
local clickdetector = script.Parent:WaitForChild("ClickDetector")
clickdetector.MouseClick:connect(function(player)
local part = Instance.new("Tool", workspace)
part.Name = "SpawnRedBlock"
local handle = Instance.new("Part",part)
handle.Name = "Handle"
handle.BrickColor = BrickColor.Red()
local BrickCD = Instance.new("ClickDetector", part)
BrickCD.Name = "RedBrickCD"
BrickCD.MouseClick:connect(function(player)
print("Red Brick")
end)
end)
The script I put in the RedRecycleBin
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "SpawnRedBlock"
then
game.workspace.SpawnRedBlock.Handle.CanCollide = false
script.Parent.Transparency = 0.5
wait(2)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
end
end)

2 comments
don't use the parent argument of instance.new, that can have adverse impacts on your game's performance
Tank you for answering even thought I dont understand exatly what you mean. In what way will it impact the performence? and is there an alternetive way to create the parts without putting them in the game from the start?