Hello, So I am making a cart system…and I want it when I click on an object to add it to cart I want it to select from 4 parts which part it should put in the cart. The others should remain transparent except the one it chose, How do I do that?
Here is a small part of the script:
local function Item()
local anitem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
wait(1)
anitem.Transparency = 0
end
local function Item()
local anitem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
task.wait(1)
for index,value in pairs(Items:GetChildren()) do
if value ~= anitem then
Value.Transparency = 1
end
end
anitem.Transparency = 0
end
local function Item()
local anitem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
task.wait(1)
for index,value in pairs(Items:GetChildren()) do
if value.Name ~= anitem.Name then -- or compare the objects
value.Transparency = 1
end
end
anitem.Transparency = 0
end
my bad, I accidentally put ‘Value’ instead of ‘value’
What exactly is it that isn’t working? Are you sure all values are correct?
I changed the script to compare instances rather than names of them, as comparing names can lead to errors since multiple instances may have the same name.
local function Item()
local anItem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
task.wait(1)
for _, child in pairs(Items:GetChildren()) do
if child ~= anItem then -- or compare the objects
child.Transparency = 1
end
end
anitem.Transparency = 0
end
local function Item()
local anItem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
print("Selected: ", anItem)
task.wait(1)
for _, child in pairs(Items:GetChildren()) do
if child ~= anItem then -- or compare the objects
child.Transparency = 1
print(child, "hidden.")
end
end
print("Showing", anItem)
anItem.Transparency = 0
end
local function Item()
local anItem = Items:GetChildren()[math.random(1, #Items:GetChildren())]
print("Selected: ", anItem)
print("Out of:", Items:GetChildren())
task.wait(1)
for _, child in pairs(Items:GetChildren()) do
print("Evaluating", child)
if child ~= anItem then -- or compare the objects
child.Transparency = 1
print(child, "hidden.")
end
end
print("Showing", anItem)
anItem.Transparency = 0
end
local Items = workspace.Items:GetChildren()
local ChosenItem = nil
local function Item()
local random = math.random(1, #Items)
local anitem = Items[random]
ChosenItem = anitem
end
workspace.Part.ClickDetector.MouseClick:Connect(function()
if ChosenItem ~= nil then
ChosenItem.Transparency = 0
end
end)