Hey!
I’ve made a shop for my game I’m working on.
I don’t want it to be too basic, so instead of just making a ScreenGui I put together a simple shop model.
Looks like this at the moment of writing:
I’m a begginer at programming, so my code was spaghetti’d together and it’s not very good…
Although super messy, it works somehow.
The way it works is, the player enters the shop by interacting with a ProximityPrompt.
To leave the shop, the player just needs to press the “Back” button on the Shop Gui.
When the player enters the shop the following code gets executed:
local RunService = game:GetService("RunService")
local TS = game:GetService("TweenService")
local CamPos = workspace.Shop.CamPos.CFrame -- Shop Cam Pos
local Camera = workspace.CurrentCamera -- Player Camera
local Player = game.Players.LocalPlayer
local PlayerLoco = Player.Character.HumanoidRootPart.CFrame -- Local Player Position
local PlayerPos = workspace.Shop.PlayerPos.CFrame -- Player Position while in Shop
local ShopGui = script.Parent.Parent.Parent -- ShopGUI
local SwipeAnimGui = script.Parent.Parent.Parent.Parent.TransitionGui.Left
-- Configure and Anchor Camera into Shop
Camera.CameraType = Enum.CameraType.Scriptable
TS:Create(Camera, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.new(-50, 0, 0)}):Play()
SwipeAnimGui:TweenPosition(UDim2.new(2, 0, 0, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Sine,
1.2,
false)
wait(.2)
Camera.CFrame = CamPos * CFrame.new(50, 0, 0)
TS:Create(Camera, TweenInfo.new(.5), {CFrame = CamPos}):Play()
wait(.5)
Camera.CFrame = CamPos
ShopGui.Enabled = true
wait(.5)
SwipeAnimGui.Position = UDim2.new(-1, 0, 0, 0)
Player.Character.HumanoidRootPart.Anchored = true
Player:SetAttribute("InShop", true)
Essentially what this script does is:
- It sets the camera as scriptable and animates it into a part (the camera position while in shop)
- Animates a GUI to give it a cool transition
- Stucks the player in place while in the shop
Now, when the player leaves the shop a similar script is executed:
local RunService = game:GetService("RunService")
local TS = game:GetService("TweenService")
local Camera = workspace.CurrentCamera
local CamPos = workspace.Shop.CamPos.CFrame
local Player = game.Players.LocalPlayer
local ShopGui = script.Parent.Parent.Parent
TS:Create(Camera, TweenInfo.new(.5), {CFrame = CamPos * CFrame.new(20, 0, 0)}):Play()
local SwipeAnimGui = script.Parent.Parent.Parent.Parent.TransitionGui.Right
SwipeAnimGui:TweenPosition(UDim2.new(-2, 0, 0, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Sine,
1.2,
false)
Player.Character.HumanoidRootPart.Anchored = false
wait(.2)
Camera.CFrame = Player.Character.Head.CFrame * CFrame.new(-20, -1, -1)
TS:Create(Camera, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {CFrame = Player.Character.Head.CFrame * CFrame.new(0, -1, -1)}):Play()
wait(.5)
Camera.CameraType = Enum.CameraType.Custom
ShopGui.Enabled = false
wait(.5)
SwipeAnimGui.Position = UDim2.new(1, 0, 0, 0)
Player:SetAttribute("InShop", false)
That’s all the code! It’s pure spagghetti (I hope it’s bearable enough).
Does anyone have suggestions of how I can improve it?
Also if this post’s quality is bad, I apologize, it’s my first time posting in the forum, I tried my best :3