I have an issue with my script.
Whenever I pick up a gun from workspace, for some reason it’s like this:
Basically, It’s tilted wrong.
(I’m also not the best at CFrames, sorry!)
Script:
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local GlockModule = Tool:WaitForChild("GlockModule"):Clone()
local Handle = Tool:WaitForChild("Handle")
local ToolName = Tool:WaitForChild("ToolName")
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local Mouse = LocalPlayer:GetMouse()
local CurrentCamera = workspace.CurrentCamera
local Modules = ReplicatedStorage:WaitForChild("Modules")
local StrafingController = require(Modules:WaitForChild("StrafingController"))
local ScreenGui = LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local ItemEquipFrame = ScreenGui:WaitForChild("ItemEquipFrame")
local SFXFolder = Handle
local EquipSFX = SFXFolder:WaitForChild("Equip")
local ShootSFX = SFXFolder:WaitForChild("Shoot")
local UnequipSFX = SFXFolder:WaitForChild("Unequip")
local ZoomSFX = SFXFolder:WaitForChild("Zoom")
local AnimationsFolder = Tool:WaitForChild("Animations")
local IdleAnim = AnimationsFolder:WaitForChild("Idle")
local ZoomAnim = AnimationsFolder:WaitForChild("Zoom")
-- Settings
local TweenInfo = TweenInfo.new(.25, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local NormalFOV = 70
local ZoomFOV = 50
local GunEquipped = false
-- Loaded Animations
local LoadedIdleAnim = Animator:LoadAnimation(IdleAnim)
local LoadedZoomAnim = Animator:LoadAnimation(ZoomAnim)
Mouse.Button2Down:Connect(function()
if GunEquipped == true then
ZoomSFX:Play()
LoadedZoomAnim:Play()
local CamTween = TweenService:Create(CurrentCamera,TweenInfo,{FieldOfView = ZoomFOV})
CamTween:Play()
end
end)
Mouse.Button2Up:Connect(function()
if GunEquipped == true then
LoadedZoomAnim:Stop()
local CamTween = TweenService:Create(CurrentCamera,TweenInfo,{FieldOfView = NormalFOV})
CamTween:Play()
end
end)
Tool.Equipped:Connect(function()
GunEquipped = true
Mouse.Icon = "rbxassetid://10397909758"
EquipSFX:Play()
LoadedIdleAnim:Play()
ScreenGui:WaitForChild("ItemEquipFrame").Visible = true
local Camera = Instance.new("Camera"); Camera.Parent = ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame")
ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame").CurrentCamera = Camera
ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ItemLabel").Text = ToolName.Value
GlockModule.Parent = ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame")
Camera.CFrame = GlockModule.CFrame * CFrame.new(1,0,0) -- I assume this or the line below it is the problem, but how would I go on to solve this?
Camera.CFrame = CFrame.new(Camera.CFrame.Position, GlockModule.Position)
StrafingController:SetEnabled(true)
end)
Tool.Unequipped:Connect(function()
GunEquipped = false
Mouse.Icon = ""
UnequipSFX:Play()
LoadedIdleAnim:Stop()
LoadedZoomAnim:Stop()
CurrentCamera.FieldOfView = NormalFOV
StrafingController:SetEnabled(false)
if ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame").Camera then
ScreenGui:WaitForChild("ItemEquipFrame").Visible = false
ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame").GlockModule.Parent = nil
ScreenGui:WaitForChild("ItemEquipFrame"):WaitForChild("ViewportFrame").Camera:Destroy()
end
end)