-
What do you want to achieve?
A Working Shop And Inventory GUI -
What is the issue?
So for the first bug, it’s a shop bug here’s the vid
So when I bought an Item, It working but it shows to all item info “Owned” even though I didn’t buy it and it shows “Purchase” even though I already bought it
For the second bug is Inventory here’s the vid
So when i try to equip an item, its working but the problem is when I already equip something and wanted to change to the other trails it’s just doesn’t work like in the video
-
What solutions have you tried so far?
Already search on social medias but no results
Here are the codes
Trail GUI Local Script
local shopBtn = script.Parent:WaitForChild("ShopButton")
local invBtn = script.Parent:WaitForChild("InventoryButton")
local tweenService = game:GetService("TweenService")
local shopFrame = script.Parent:WaitForChild("ShopFrame")
local invFrame = script.Parent:WaitForChild("InventoryFrame")
local Sound = script.Parent.InventoryButton.Sound
local debounce = false
local TrailPage = shopFrame.ListPages.TrailPage
local InventoryTrailPage = invFrame.ListPages.TrailPage
local InventoryScrollingTrail = invFrame.InventoryScrollingTrail
local ShopScrollingTrail = shopFrame.ShopScrollingTrail
local ShopScrollingSword = shopFrame.ShopScrollingSwords
local player = game.Players.LocalPlayer
local Notif = script.Parent.Notif
shopBtn.MouseButton1Click:Connect(function()
Sound:Play()
shopFrame.Visible = not shopFrame.Visible; invFrame.Visible = false
end)
invBtn.MouseButton1Click:Connect(function()
Sound:Play()
invFrame.Visible = not invFrame.Visible; shopFrame.Visible = false
if Notif.Value == true then
Notif.Value = false
script.Parent.InventoryButton.Notification.Visible = false
end
end)
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
local trailsFolder = game.ReplicatedStorage:WaitForChild("Trails")
local ownedTrailsFolder = game.Players.LocalPlayer:WaitForChild("OwnedTrails")
local InfoItem = script.Parent.ShopFrame.InfoItem
function updateInventory()
for i, child in pairs(InventoryScrollingTrail:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
local InfoItem = script.Parent.InventoryFrame.InfoItem
InfoItem.Button.Visible = false
InfoItem.ViewportFrame.Visible = false
InfoItem.ItemName.Visible = false
local ownedTrails = ownedTrailsFolder:GetChildren()
table.sort(ownedTrails, function(a, b)
return trailsFolder[a.Name].Price.Value < trailsFolder[b.Name].Price.Value or trailsFolder[a.Name].Price.Value == trailsFolder[b.Name].Price.Value and a.Name < b.Name
end)
for i, trail in pairs(ownedTrails) do
local item = script.Item:Clone()
item.Trail.UIGradient.Color = trail.Color
item.Parent = InventoryScrollingTrail
item.MouseButton1Click:Connect(function()
Sound:Play()
InfoItem.ViewportFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
InfoItem.ItemName.Text = trail.Name
InfoItem.ViewportFrame.UIGradient.Color = trail.Color
InfoItem.Button.BText.Text = "EQUIP"
InfoItem.ViewportFrame.Visible = true
InfoItem.ItemName.Visible = true
InfoItem.Button.Visible = true
if game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"):FindFirstChild(trail.Name) then
InfoItem.Button.BText.Text = "EQUIPPED"
end
InfoItem.Button.MouseButton1Click:Connect(function()
Sound:Play()
game.ReplicatedStorage.TrailSelectedRE:FireServer(false, trail)
if trail.Name ~= game.Players.LocalPlayer.CurrentTrail.Value then
InfoItem.Button.BText.Text = "EQUIPPED"
else
InfoItem.Button.BText.Text = "EQUIP"
end
end)
end)
end
end
function updateShop()
for _, child in pairs(ShopScrollingTrail:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
local shopTrails = trailsFolder:GetChildren()
table.sort(shopTrails, function(a, b)
return a.Price.Value < b.Price.Value or a.Price.Value == b.Price.Value and a.Name < b.Name
end)
local InfoItem = script.Parent.ShopFrame.InfoItem
for _, trail in pairs(shopTrails) do
local item = script.Item:Clone()
item.Trail.UIGradient.Color = trail.Color
item.Parent = ShopScrollingTrail
InfoItem.Button.BText.Text = "Purchase"
item.MouseButton1Click:Connect(function()
Sound:Play()
InfoItem.ViewportFrame.Visible = true
InfoItem.ItemName.Visible = true
InfoItem.Button.Visible = true
InfoItem.Price.Visible = true
if ownedTrailsFolder:FindFirstChild(trail.Name) then InfoItem.Button.BText.Text = "Owned" end
InfoItem.ViewportFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
InfoItem.ItemName.Text = trail.Name
InfoItem.ViewportFrame.UIGradient.Color = trail.Color
InfoItem.Price.Text = comma_value(trail.Price.Value) .. " Coins"
InfoItem.Button.MouseButton1Click:Connect(function()
if ownedTrailsFolder:FindFirstChild(trail.Name) then InfoItem.Button.BText.Text = "Owned" end
if not debounce then
debounce = true
Sound:Play()
game.ReplicatedStorage.TrailSelectedRE:FireServer(true, trail, script.Parent.NotificationBar, Notif, script.Parent.Notification)
task.wait(4)
debounce = false
end
end)
end)
end
end
game.ReplicatedStorage.TrailSelectedRE.OnClientEvent:Connect(function(plr)
script.Parent.Notification:Play()
end)
updateShop()
updateInventory()
ownedTrailsFolder.ChildAdded:Connect(function(item)
local info = TweenInfo.new(0.5)
local tween = tweenService:Create(script.Parent.NotificationBar, info, {TextTransparency = 1, BackgroundTransparency = 1, TextStrokeTransparency = 1 })
local tween2 = tweenService:Create(script.Parent.NotificationBar.UIStroke, info, {Transparency = 1})
script.Parent.Notification:Play()
script.Parent.InventoryButton.Notification.Visible = true
Notif.Value = true
script.Parent.NotificationBar.Visible = true
script.Parent.NotificationBar.Text = " Purchased New Item: <font color=\"rgb(85,255,0)\">" .. item.Name .. " Trail </font>"
updateInventory(); updateShop()
task.wait(3.5)
tween2:Play()
tween:Play()
local NotificationBar = script.Parent.NotificationBar
local function Invisible()
NotificationBar.BackgroundTransparency = 0
NotificationBar.TextTransparency = 0
NotificationBar.TextStrokeTransparency = 0
NotificationBar.UIStroke.Transparency = 0
NotificationBar.Visible = false
end
tween.Completed:Connect(function()
Invisible()
end)
tween2.Completed:Connect(function()
Invisible()
end)
end)
ownedTrailsFolder.ChildRemoved:Connect(function()
updateInventory(); updateShop()
end)
trailsFolder.ChildAdded:Connect(updateShop)
trailsFolder.ChildRemoved:Connect(updateShop)
Trail Applier Server Script
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("1")
local trails = game.ReplicatedStorage:WaitForChild("Trails")
local tweenService = game:GetService("TweenService")
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
function createAtchs(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local atchTop = Instance.new("Attachment", hrp)
atchTop.Name = "TrailTop"
atchTop.Position = Vector3.new(0, 0.82, 0)
local atchBtm = Instance.new("Attachment", hrp)
atchBtm.Name = "TrailBottom"
atchBtm.Position = Vector3.new(0, -0.8, 0)
if game.Players:GetPlayerFromCharacter(char).CurrentTrail.Value ~= "" then
local newTrail = game.ReplicatedStorage.Trails[game.Players:GetPlayerFromCharacter(char).CurrentTrail.Value]:Clone()
newTrail.Attachment0 = char.HumanoidRootPart.TrailTop
newTrail.Attachment1 = char.HumanoidRootPart.TrailBottom
newTrail.Parent = char.HumanoidRootPart
end
end
function saveData(plrLeaving)
local ownedTrails = {}
for i, trail in pairs(plrLeaving.OwnedTrails:GetChildren()) do
table.insert(ownedTrails, trail.Name)
end
local success, err = pcall(function()
ds:SetAsync("trails-" .. plrLeaving.UserId, {ownedTrails, plrLeaving.CurrentTrail.Value})
end)
end
game.Players.PlayerAdded:Connect(function(plr)
local trailsOwned = {}
local trailEquipped = ""
pcall(function()
trailsOwned = ds:GetAsync("trails-" .. plr.UserId)[1] or {}
trailEquipped = ds:GetAsync("trails-" .. plr.UserId)[2] or ""
end)
local ownedFolder = Instance.new("Folder", plr)
ownedFolder.Name = "OwnedTrails"
local currentTrail = Instance.new("StringValue", plr)
currentTrail.Name = "CurrentTrail"
currentTrail.Value = trailEquipped
for i, owned in pairs(trailsOwned) do
if trails:FindFirstChild(owned) then
trails[owned]:Clone().Parent = ownedFolder
end
end
if plr.Character then createAtchs(plr.Character) end
plr.CharacterAdded:Connect(createAtchs)
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, plrLeaving in pairs(game.Players:GetPlayers()) do
saveData(plrLeaving)
end
end)
game.ReplicatedStorage.TrailSelectedRE.OnServerEvent:Connect(function(plr, buying, trail, NotificationBar, Notif)
if buying and not plr.OwnedTrails:FindFirstChild(trail.Name) then
local price = trail.Price.Value
local money = plr.Money
if price <= money.Value then
money.Value -= price
local char = plr.Character
if not char or not char:FindFirstChild("HumanoidRootPart") then return end
for _, child in pairs(char.HumanoidRootPart:GetChildren()) do
if child:IsA("Trail") then
if child.Name ~= trail.Name then
child:Destroy()
else
child:Destroy()
plr.CurrentTrail.Value = ""
return
end
end
end
local newTrail = trail:Clone()
newTrail.Attachment0 = char.HumanoidRootPart.TrailTop
newTrail.Attachment1 = char.HumanoidRootPart.TrailBottom
newTrail.Parent = char.HumanoidRootPart
plr.CurrentTrail.Value = newTrail.Name
trail:Clone().Parent = plr.OwnedTrails
elseif price >= money.Value then
game.ReplicatedStorage.TrailSelectedRE:FireClient(plr)
local info = TweenInfo.new(0.5)
local tween = tweenService:Create(NotificationBar, info, {TextTransparency = 1, BackgroundTransparency = 1, TextStrokeTransparency = 1 })
local tween2 = tweenService:Create(NotificationBar.UIStroke, info, {Transparency = 1})
Notif.Value = true
NotificationBar.Visible = true
NotificationBar.Text = " Need <font color=\"rgb(255,170,0)\">" .. comma_value(price - money.Value) .. "</font> More Coins To Purchase This Item "
task.wait(3.5)
tween2:Play()
tween:Play()
tween.Completed:Connect(function()
NotificationBar.BackgroundTransparency = 0
NotificationBar.TextTransparency = 0
NotificationBar.TextStrokeTransparency = 0
NotificationBar.UIStroke.Transparency = 0
NotificationBar.Visible = false
end)
tween2.Completed:Connect(function()
NotificationBar.BackgroundTransparency = 0
NotificationBar.TextTransparency = 0
NotificationBar.TextStrokeTransparency = 0
NotificationBar.UIStroke.Transparency = 0
NotificationBar.Visible = false
end)
end
elseif not buying and plr.OwnedTrails:FindFirstChild(trail.Name) then
local char = plr.Character
if not char or not char:FindFirstChild("HumanoidRootPart") then return end
for _, child in pairs(char.HumanoidRootPart:GetChildren()) do
if child:IsA("Trail") then
if child.Name ~= trail.Name then
child:Destroy()
else
child:Destroy()
plr.CurrentTrail.Value = ""
return
end
end
end
local newTrail = trail:Clone()
newTrail.Attachment0 = char.HumanoidRootPart.TrailTop
newTrail.Attachment1 = char.HumanoidRootPart.TrailBottom
newTrail.Parent = char.HumanoidRootPart
plr.CurrentTrail.Value = newTrail.Name
end
end)
No Errors appear on the output
Local Script placed inside the ScreenGUI
Server Script placed inside the ServerScriptService
Any helps would be appreciated