What I’m trying to achieve
I’m trying to make a vending machine which functions when the code is correct it gives an item, however, when it goes to get the children and clone the item it gives an error. Any help is appreciated!
My code:
local Tools = script.Parent.Tools
local Selections = script.Parent.Selections
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local enter = script.Parent.Screen.SurfaceGui.Select.Enter
local cancel = script.Parent.Screen.SurfaceGui.Select.Cancel
local UIinfo = TweenInfo.new(
0.1, --Time
Enum.EasingStyle.Sine, -- Style of door open animation
Enum.EasingDirection.InOut, -- Direction of easing.
0, -- Repeat count.
false, -- Will it reverse?
0 -- The delay time.
)
if game.IsLoaded then
Tools.Parent = ReplicatedStorage
end
local result = ""
for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
if not v:IsA("TextButton") then continue end
local uithickness = v.UIStroke
local tweenenter = TweenService:Create(uithickness, UIinfo, {Thickness = 4})
local tweenleave = TweenService:Create(uithickness, UIinfo, {Thickness = 2})
v.MouseEnter:Connect(function()
tweenleave:Cancel()
tweenenter:Play()
end)
v.MouseLeave:Connect(function()
tweenenter:Cancel()
tweenleave:Play()
end)
v.MouseButton1Down:Connect(function()
if v.Name == "Enter" then
print(result)
if Selections:FindFirstChild(result) then
print("Found".. result)
-- Clones the item
-- Where I'm trying to clone
local item = Selections:FindFirstChild(result).Item:GetChildren()
item:Clone()
item.Position = result.Dropper
elseif not Selections:FindFirstChild(result) then
print("Not found!")
script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = "Item does not exist."
wait(2)
script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = result
end
elseif v.Name == "Cancel" then
result = ""
script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = "__"
else
result ..= v.Text
script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = result
end
end)
end