I made a weapons shop script and it's being weird. Basically when i make it tween to item number 2, the camera tweens but it is at a side view. How can I fix this?
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local tweenservice = game:GetService("TweenService")
local currentitem = 1
local finished = nil
script.Parent.NextFrame.NextButton.MouseButton1Click:Connect(function()
currentitem = currentitem + 1
if currentitem > 5 then
currentitem = 0
else
finished = workspace.SwordCameras[currentitem]
local tween = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false)
local goal = {CFrame = CFrame.new(finished.Position)}
local Tween = tweenservice:Create(cam, tween, goal)
Tween:Play()
end
end)
script.Parent.PreviousFrame.PreviousButton.MouseButton1Click:Connect(function()
currentitem = currentitem - 1
if currentitem < 0 then
currentitem = 5
else
finished = workspace.SwordCameras[currentitem]
local tween = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false)
local goal = {CFrame = CFrame.new(finished.Position)}
local Tween = tweenservice:Create(cam, tween, goal)
Tween:Play()
end
end)
script.Parent.Purchase.Purchase.MouseButton1Click:Connect(function()
if currentitem == 1 then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local plr = plrs[i]
local clone = game.ReplicatedStorage.Items["Sharp Sword"]:Clone()
if plr.Backpack:FindFirstChild('Sharp Sword') then
return nil
else
clone.Parent = plr.Backpack
end
end
elseif currentitem == 2 then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local plr = plrs[i]
local clone = game.ReplicatedStorage.Items["Knights Sword"]:Clone()
if plr.Backpack:FindFirstChild('Knights Sword') then
return nil
else
clone.Parent = plr.Backpack
end
end
elseif currentitem == 3 then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local plr = plrs[i]
local clone = game.ReplicatedStorage.Items["Hero Sword"]:Clone()
if plr.Backpack:FindFirstChild('Hero Sword') then
return nil
else
clone.Parent = plr.Backpack
end
end
elseif currentitem == 4 then
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local plr = plrs[i]
local clone = game.ReplicatedStorage.Items["Hero Sword"]:Clone()
if plr.Backpack:FindFirstChild('Hero Sword') then
return nil
else
clone.Parent = plr.Backpack
end
end
end
end)
