So I made a shop and it looks good. How can I make it better?
Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Camera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local pastPosition = script.Parent.ShopFrame.Position
ReplicatedStorage.Events.ShopOpen.OnClientEvent:Connect(function(shop,info,prompt)
prompt.Enabled = false
local ogPos = script.Parent.ShopFrame.Icon.Position
local pastCFrame = Camera.CFrame
local pastSize = script.Parent.ShopFrame.Icon.Size
local index = 0
local closed = false
Camera.CameraType = Enum.CameraType.Scriptable
script.Parent.ShopFrame.Position = pastPosition - UDim2.new(1,0,0,0)
local MusicFadeOutTween = TweenService:Create(game.SoundService.Music.MainMusic, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Volume = 0})
local MusicFadeInTween = TweenService:Create(game.SoundService.Music.MainMusic, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Volume = 1})
local EnterFrameTween = TweenService:Create(script.Parent.ShopFrame, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = pastPosition})
local ExitFrameTween = TweenService:Create(script.Parent.ShopFrame, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = pastPosition + UDim2.new(1,0,0,0)})
local EnterTween = TweenService:Create(Camera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = shop.CameraPos.CFrame})
local ExitTween = TweenService:Create(Camera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = pastCFrame})
EnterTween:Play()
print(info)
game.SoundService.Music.ShopMusic:Play()
local function playSound(soundId)
local sound = Instance.new("Sound")
sound.Parent = game.SoundService.NewSoundFolder
sound.SoundId = soundId
sound.Volume = 1
sound:Play()
sound.Loaded:Wait()
task.delay(sound.TimeLength + 0.05, function()
if sound then sound:Destroy() end
end)
end
local function randomQuote()
script.Parent.ShopFrame.Icon.Position = ogPos + UDim2.new(0,0,0,-20)
local talkTween = TweenService:Create(script.Parent.ShopFrame.Icon, TweenInfo.new(0.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = ogPos})
local quotes = info["Quotes"]
local random = math.random(1, #quotes)
local soundId = info["TalkSound"]
talkTween:Play()
script.Parent.ShopFrame.Icon.QuoteText.Text = quotes[random]
task.spawn(playSound, soundId)
end
local function randomBuyQuote()
script.Parent.ShopFrame.Icon.Position = ogPos + UDim2.new(0,0,0,-20)
local talkTween = TweenService:Create(script.Parent.ShopFrame.Icon, TweenInfo.new(0.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = ogPos})
local quotes = info["SuccessBuyQuotes"]
local random = math.random(1, #quotes)
local soundId = info["TalkSound"]
talkTween:Play()
script.Parent.ShopFrame.Icon.QuoteText.Text = quotes[random]
task.spawn(playSound, soundId)
end
local function randomFailBuyQuote()
script.Parent.ShopFrame.Icon.Position = ogPos + UDim2.new(0,0,0,-20)
local talkTween = TweenService:Create(script.Parent.ShopFrame.Icon, TweenInfo.new(0.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = ogPos})
local quotes = info["FailBuyQuotes"]
local random = math.random(1, #quotes)
local soundId = info["TalkSound"]
talkTween:Play()
script.Parent.ShopFrame.Icon.QuoteText.Text = quotes[random]
task.spawn(playSound, soundId)
end
local function randomSquishQuote()
local quotes = info["SquishQuotes"]
local random = math.random(1, #quotes)
local soundId = info["TalkSound"]
task.spawn(playSound, soundId)
script.Parent.ShopFrame.Icon.QuoteText.Text = quotes[random]
end
local function setupIcon()
script.Parent.ShopFrame.Icon.Image = info["Icon"]
randomQuote()
local connection = script.Parent.ShopFrame.Icon.MouseButton1Click:Connect(function()
script.Parent.ShopFrame.Icon.Size = pastSize + UDim2.new(0,50,0,-50)
local squishTween = TweenService:Create(script.Parent.ShopFrame.Icon, TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Size = pastSize})
local soundId = game.SoundService.SFX.Squish.SoundId
squishTween:Play()
randomSquishQuote()
print("press")
task.spawn(playSound, soundId)
end)
task.spawn(function()
while task.wait() do
if closed then connection:Disconnect() break end
end
end)
end
script.Parent.Enabled = true
setupIcon()
MusicFadeOutTween:Play()
EnterFrameTween:Play()
for _, v in ipairs(script.Parent:GetDescendants()) do
if v:IsA("ImageButton") and v:HasTag("ShopButton") then
index += 1
local itemIndex = index
local itemInfo = info["Items"][itemIndex]
local price = itemInfo.Price
local itemFrame = script.Parent.ShopFrame["Item"..itemIndex]
itemFrame.Image = itemInfo.Icon
itemFrame["Item"..itemIndex.."Label"].Text = itemInfo.Name.. " $".. price
local connection2 = v.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Cash.Value >= price then
randomBuyQuote()
task.spawn(playSound, game.SoundService.SFX.BuyItem.SoundId)
ReplicatedStorage.Events.BuyItem:FireServer(itemInfo.ItemName, price)
else
randomFailBuyQuote()
end
end)
task.spawn(function()
while task.wait() do
if closed then
connection2:Disconnect()
break
end
end
end)
end
end
local connection
connection = script.Parent.ShopFrame.CloseButton.MouseButton1Click:Connect(function()
ExitTween:Play()
connection:Disconnect()
closed = true
game.SoundService.Music.ShopMusic:Stop()
game.SoundService.SFX.Bye:Play()
ExitFrameTween:Play()
ExitTween.Completed:Wait()
MusicFadeInTween:Play()
script.Parent.Enabled = false
prompt.Enabled = true
Camera.CameraType = Enum.CameraType.Custom
end)
end)
Server
local Shops = workspace:WaitForChild("Shops")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
for i,shop in Shops:GetDescendants() do
if shop:IsA("Model") then
if shop:HasTag("Shop") then
for i,v in shop:GetDescendants() do
if v:IsA("BasePart") then
if v.Name == "ShopPrompt" then
local ProximityPrompt = Instance.new("ProximityPrompt")
local ShopInfo = v:WaitForChild("ShopInfo")
ProximityPrompt.Parent = v
ProximityPrompt.ActionText = "Open"
ProximityPrompt.ObjectText = "Shop"
ProximityPrompt.Triggered:Connect(function(player)
ReplicatedStorage.Events.ShopOpen:FireClient(player, shop, require(ShopInfo), ProximityPrompt)
end)
end
end
end
end
end
end
Module
local shopinfo = {
["Items"] = {
[1] = {
Name = "Teddy Bear",
ItemName = "Teddy",
Icon = "rbxassetid://8073107221",
Price = 20
},
[2] = {
Name = "Teddy Bear",
ItemName = "Teddy",
Icon = "rbxassetid://8073107221",
Price = 20
},
[3] = {
Name = "Teddy Bear",
ItemName = "Teddy",
Icon = "rbxassetid://8073107221",
Price = 20
},
[4] = {
Name = "Teddy Bear",
ItemName = "Teddy",
Icon = "rbxassetid://8073107221",
Price = 20
},
[5] = {
Name = "Teddy Bear",
ItemName = "Teddy",
Icon = "rbxassetid://8073107221",
Price = 20
},
[6] = {
Name = "...",
ItemName = "AK47",
Icon = "rbxassetid://9822883942",
Price = 20
},
},
["Icon"] = "rbxassetid://115838236744256",
["TalkSound"] = "rbxassetid://5417004822",
["Quotes"] = {
"hi",
"yo whats up",
"eeeeeeeee"
},
["SuccessBuyQuotes"] = {
"yoo thanks",
"thank you!",
"ur the best"
},
["FailBuyQuotes"] = {
"oh you cant afford that lol",
"bruh when will i get the money",
"aw man"
},
["SquishQuotes"] = {
"ow",
"stop",
"ah",
"what"
}
}
return shopinfo
Don’t mind the unnecessary quotes, items, and music. The game was just a test.