For my simulator game, I’ve tried to made a shop system. (I’ve never made something like this before)
Basically, you start with item 1 and you cant get item 3 until you get item 2, etc.
I’ve made a buy function and a (broken) equip function, but the buttons dont seem to be firing.
The thing is, everything is working fine except for when I buy. It buys it and then after that the connection to the buttons being clicked gets disconnected.
I do not understand why this is happening and any help would be appreciated.
I have not found any answers on dev hub or searching.
Here are my scripts:
ShopModule.lua (ModuleScript in game > ReplicatedStorage > Assets > Modules)
-- made by recanman
local sm = {}
local db
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)
print(child.Name)
--if (child)
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
sm:Initialize(infoFrame.Parent)
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() -- broken, fix
db = true
print(child.Name)
plr.CurrentTaser.Value = child.Name
plr.Character.Humanoid:UnequipTools()
plr.Backpack:ClearAllChildren()
game.ReplicatedStorage.Assets.Tasers[child.Name]:Clone().Parent = plr.Backpack
sm:Initialize(infoFrame.Parent)
end)
db = false
end)
end
wait()
infoFrame.Visible = true
end
return sm
TaserBuy.lua (script located in game > ServerScriptService > CoreGameScripts)
-- made by recanman
local ds2 = require(1936396537) -- ds2 module
game.ReplicatedStorage.Assets.Events.TaserBuyEvent.OnServerEvent:Connect(function(plr, taser)
local taserDs = ds2("Tasers", plr)
local currentTaser = game.ReplicatedStorage.Assets.Events.DataStoreTaserCheckEvent.InformHandler:Invoke(plr)
if (currentTaser + 1 == game.ReplicatedStorage.Assets.Tasers[taser].Settings.Order.Value) then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - game.ReplicatedStorage.Assets.Tasers[taser].Settings.Cost.Value
taserDs:Increment(1)
end
end)
ShopHandler.lua (located in game > StarterGui > Main > MainFrame > ShopFrame2 > Frame > List)
-- made by recanman
local sm = require(game.ReplicatedStorage.Assets.Modules.ShopModule)
script.Parent:WaitForChild("ItemStorage")
sm:Initialize(script.Parent.Parent)
for _, child in ipairs(script.Parent.ItemStorage:GetChildren()) do
if (child:IsA("TextButton") and child.Locked.Visible ~= true) then
child.MouseButton1Click:Connect(function()
sm:ShowInfoFrame(child, game.Players.LocalPlayer, script.Parent.Parent.InfoFrame)
end)
end
end
Also I have to click the buy button 2 times for it to fire I don’t know why.
Why is no one answering this…? 100 views