Hey so I’ve got this little shop thing here. I don’t know what to call it so I’ll just link a video:
Now this works exactly how I want it to, however I know I’m not doing this in the most efficient way possible, and I’m also planning on adding in like 30 different slots to this shop. Here is my code to make this work:
– Note this is a LocalScript located in StarterPlayerScripts.
game.Players.LocalPlayer.PlayerGui:WaitForChild("ChoosePowerUpUI").NextButtonRight.MouseButton1Click:Connect(function()
if currentCamNumber == 1 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart2.CFrame})
currentCamNumber = 2
unlockButton.Text = "Unlock: Katana"
Tween:Play()
print(currentCamNumber)
elseif currentCamNumber == 2 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart3.CFrame})
currentCamNumber = 3
unlockButton.Text = "Unlock: Double Daggers"
Tween:Play()
print(currentCamNumber)
elseif currentCamNumber == 3 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart4.CFrame})
currentCamNumber = 4
unlockButton.Text = "Unlock: Bo Staff"
Tween:Play()
print(currentCamNumber)
elseif currentCamNumber == 4 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart5.CFrame})
currentCamNumber = 5
unlockButton.Text = "Unlock: Trident of Darkness"
Tween:Play()
print(currentCamNumber)
elseif currentCamNumber == 5 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart6.CFrame})
currentCamNumber = 6
unlockButton.Text = "Unlock: Aaron"
Tween:Play()
print(currentCamNumber)
elseif currentCamNumber == 6 then
local Tween = game:GetService("TweenService"):Create(camera, tweeninfo, {CFrame = cameraPart1.CFrame})
currentCamNumber = 1
unlockButton.Text = "Unlock: Pistol"
Tween:Play()
print(currentCamNumber)
end
end)
currentCamera
refers to a variable I added at the top of the code to track which spot in the shop the player was on, so if the player was on the first powerup of the shop, they would be in the first slot, so currentCamera
would be set to 1.
Not only do I want that part to be more efficient if possible, but as you can see I’m also creating a new tween every single time, and I was wondering if there was another way to do this, but considering that I have a different position for each tween, that may not be possible.
Like I said, everything works perfectly fine, which is why I’m posting it here, I just to know how I could make this more efficient. I’ll try to answer any of your questions. If you need more code, you can ask me because this is only one part of it. Thanks for looking over this!