I’m trying to make a shop system.
Everything is going fine, until this happens.
When I run the function :Initialize(frame), it returns this error:
Locked is not a valid member of TextButton
When I print textbutton:GetChildren() then it literally shows “Locked”
Here is my code, any help would be appreciated, thanks!
ShopModule.lua
-- made by recanman
local sm = {}
local db = false
function sm:Initialize(frame)
for _, child in ipairs(frame.List.ItemStorage:GetChildren()) do
if (child:IsA("TextButton")) then
child:Destroy()
end
end
frame.InfoFrame.Visible = false
for _, child in ipairs(game.ReplicatedStorage.Assets.Tasers:GetChildren()) do
local template = game.ReplicatedStorage.Assets.Other.Template:Clone()
template.Name = child.Name
template.PetFrame.PetDisplay.PetName.Text = child.Name
template.Parent = frame.List.ItemStorage
local vpfTaser = game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone()
local model = Instance.new("Model")
template.PetFrame.PetDisplay:FindFirstChildOfClass("Model"):Destroy()
model.Parent = template.PetFrame.PetDisplay
for _, child in ipairs(vpfTaser:GetChildren()) do
child.Parent = model
end
model.PrimaryPart = model.Handle
model.TaserScript:Destroy()
model.Parent = template.PetFrame.PetDisplay
model:SetPrimaryPartCFrame(CFrame.new(-0.348, 0.695, -85.803))
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(0), math.rad(40), math.rad(45)))
template.LayoutOrder = child.Settings.Order.Value
local isUnlocked = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent:InvokeServer()
if (isUnlocked + 1 >= template.LayoutOrder) then
child.Settings.Locked.Value = false
else
child.Settings.Locked.Value = true
end
if (child.Settings.Locked.Value == true) then
template.Locked.Visible = true
template.PetFrame.PetDisplay.Visible = false
else
template.Locked.Visible = false
template.PetFrame.PetDisplay.Visible = true
end
end
end
function sm:ShowInfoFrame(child, plr, infoFrame)
infoFrame.Visible = false
infoFrame.Equipped.Visible = false
infoFrame.Equip.Visible = false
infoFrame.BuyNow.Visible = false
infoFrame.PetDisplay.PetName.Text = child.Name
infoFrame.Stats.Cost.Text = game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value
infoFrame.Stats.CoinsPerClick.Text = game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.CoinsPerClick.Value
local vpfTaser = game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone()
local model = Instance.new("Model")
infoFrame.PetDisplay:FindFirstChildOfClass("Model"):Destroy()
model.Parent = infoFrame.PetDisplay
for _, child in ipairs(vpfTaser:GetChildren()) do
child.Parent = model
end
model.PrimaryPart = model.Handle
model.TaserScript:Destroy()
model.Parent = infoFrame.PetDisplay
model:SetPrimaryPartCFrame(CFrame.new(-0.348, 0.695, -85.803))
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(0), math.rad(40), math.rad(45)))
local currentTaser = plr.CurrentTaser.Value
local isUnlocked = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent:InvokeServer()
if (child.Name == currentTaser) then
infoFrame.Equipped.Visible = true
end
if (isUnlocked >= child.LayoutOrder) then
infoFrame.Equip.Visible = true
elseif (isUnlocked + 1 == child.LayoutOrder) then
infoFrame.BuyNow.Visible = true
infoFrame.BuyNow.MouseButton1Click:Connect(function()
if (db == false and plr.leaderstats.Coins.Value >= game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value) then
db = true
game.ReplicatedStorage.Assets.Events.TaserBuyEvent:FireServer(child.Name)
plr.CurrentTaser.Value = child.Name
plr.Character.Humanoid:UnequipTools()
plr.Backpack:ClearAllChildren()
game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone().Parent = plr.Backpack
coroutine.wrap(function() sm:Initialize(infoFrame.Parent) end)()
elseif (plr.leaderstats.Coins.Value < game.ReplicatedStorage.Assets.Tasers[child.Name].Settings.Cost.Value) then
local tween = game:GetService("TweenService"):Create(infoFrame.BuyNow.AvailableIn, TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 2, true, 0), {TextColor3 = Color3.new(1, 0, 0)})
tween:Play()
end
infoFrame.Equip.MouseButton1Click:Connect(function()
db = true
game.ReplicatedStorage.Assets.Events.EquipEvent:FireServer(infoFrame.PetDisplay.PetName.Text)
plr.Character.Humanoid:UnequipTools()
plr.Backpack:ClearAllChildren()
wait(1)
for _, child in ipairs(infoFrame.Parent.List.ItemStorage:GetChildren()) do
if (child:IsA("TextButton")) then
child:Destroy()
end
end
sm:Initialize(infoFrame.Parent)
end)
wait()
db = false
end)
end
wait()
infoFrame.Visible = true
end
return sm
The :ShowInfoFrame() function is being run, and the Equip button is being clicked. It fires the event, then does the Initialize function, which refreshes it.