You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Im trying to add a leaning to my viewmodel but it doesnt work
-
What is the issue? Just leaning doesnt happen
-
What solutions have you tried so far? Leaning is not a popular thing soo I couldnt find something usefull
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-------SERVİCES----------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
-----PLAYER-INSTANCES-----
local Player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local PlayerGui = Player.PlayerGui
local GunGUI = PlayerGui:WaitForChild("GunGUI").Frame
local AmmoValues = GunGUI.AmmoValues
------MODULES-----
local EquipGunViewModel = require(ReplicatedStorage.Modules.EquipGunViewModel)
local BulletModule = require(ReplicatedStorage.Modules.BulletModule)
local SpringModule = require(ReplicatedStorage.Modules.SpringModule)
-------EVENTS---------
local BulletHandle = ReplicatedStorage.Events.BulletHandle
local ReloadGunCharacter = ReplicatedStorage.Events.ReloadGunCharacter
local LoadOut = require(Player.PlayerGui:WaitForChild("LoadOut").Slots)
---VARİABLES-----
local isHoldingMouseButton1 = false
local isAiming = false
local isReloading = false
local isLeaning = false
local leaningSide = nil
local canFire = true
local gunConfig
local CurrentGun = LoadOut.primary.Name
local CurrentAmmo
-----MATH-STUFF-IDK------------
local RecoilSpring = SpringModule.new()
local BobbingSpring = SpringModule.new()
local SwayingSpring = SpringModule.new()
local updatedRecoilSpring = CFrame.new()
local updatedBobbingSpring = CFrame.new()
local updatedSwaySpring = CFrame.new()
ReplicatedStorage:FindFirstChild(LoadOut.viewmodel):Clone().Parent = game.Workspace.Camera
local ViewModel = Camera[LoadOut.viewmodel]
local function getBobbing(addition)
return math.sin(tick() * addition * 1.3) * .5
end
BulletHandle.OnClientEvent:Connect(function(player, origin, endposition, gunName)
if player ~= game.Players.LocalPlayer then
task.spawn(function()
print(gunName)
for i,v in pairs(player.Character:WaitForChild(gunName).Barrel:GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit()
elseif v:IsA("PointLight") then
v.Enabled = true
wait(.1)
v.Enabled = false
end
end
gunConfig.fireSound:Play()
end)
local sentByOrigin = false
BulletModule.bullet(player, origin, endposition, gunConfig, sentByOrigin)
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
local Bobbing = Vector3.new(getBobbing(10), getBobbing(5), getBobbing(5))
local Character = Player.Character or Player.CharacterAdded:Wait()
local MouseDelta = UserInputService:GetMouseDelta()
BobbingSpring:shove(Bobbing / 20 * (Character.HumanoidRootPart.Velocity.Magnitude) / 20)
SwayingSpring:shove(Vector3.new(-MouseDelta.X / 500, MouseDelta.Y / 200, 0))
ViewModel.FakeCamera.CFrame = game.Workspace.Camera.CFrame:ToWorldSpace(CFrame.new(updatedBobbingSpring.Y, updatedBobbingSpring.X, 0)) * CFrame.Angles(math.rad(updatedRecoilSpring.X)*4, 0, 0)
Camera.CFrame = Camera.CFrame * CFrame.Angles(math.rad(updatedRecoilSpring.X), math.rad(updatedRecoilSpring.Y), math.rad(updatedRecoilSpring.Z))
ViewModel.FakeCamera.CFrame *= CFrame.new(updatedSwaySpring.X, updatedSwaySpring.Y, 0)
if isLeaning == true then
if leaningSide == "Right" then
else
ViewModel.FakeCamera.CFrame = ViewModel.FakeCamera.CFrame:Lerp(ViewModel.FakeCamera.CFrame * CFrame.Angles(0, 0, math.rad(45)), 0.1)
Camera.CFrame = Camera.CFrame:Lerp(ViewModel.FakeCamera.CFrame * CFrame.Angles(0, 0, math.rad(45)), 0.1) --This part is for Leaning but it doesnt make it really work like aiming idk how to explain check the video
end
end
--- Aiming part as I said works smoothly
if isAiming == true then
ViewModel.FakeCamera.Position = ViewModel.FakeCamera.Position:Lerp(ViewModel[CurrentGun].AimPart.Position, 0.2)
else
ViewModel.FakeCamera.Position = ViewModel.FakeCamera.Position:Lerp(ViewModel.HumanoidRootPart.Position, 0.1)
end
updatedRecoilSpring = RecoilSpring:update(deltaTime)
updatedBobbingSpring = BobbingSpring:update(deltaTime)
updatedSwaySpring = SwayingSpring:update(deltaTime)
end)
RunService.Heartbeat:Connect(function(deltaTime)
GunGUI.Mag.Text = gunConfig.magAmmo
if isHoldingMouseButton1 == true then
if canFire == true and gunConfig.magAmmo ~= 0 and gunConfig.magAmmo > 0 and isReloading == false then
if gunConfig.fireMode == "Semi" then
isHoldingMouseButton1 = false
end
canFire = false
RecoilSpring:shove(Vector3.new(gunConfig.UpRecoils[1],math.random(gunConfig.LeftRightRecoils[1],gunConfig.LeftRightRecoils[2])),gunConfig.RecoilShake)
coroutine.wrap(function()
wait(0.2)
RecoilSpring:shove(Vector3.new(gunConfig.UpRecoils[2],math.random(gunConfig.WrapLeftRightRecoils[1],gunConfig.WrapLeftRightRecoils[2]),-gunConfig.RecoilShake))
end)
task.spawn(function()
gunConfig.fireSound:Play()
for i,v in pairs(ViewModel[CurrentGun].Barrel:GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit()
elseif v:IsA("PointLight") then
v.Enabled = true
wait(.1)
v.Enabled = false
end
end
end)
local CastParams = RaycastParams.new()
CastParams.IgnoreWater = true
--CastParams.FilterType = Enum.RaycastFilterType.Blacklist
CastParams.FilterDescendantsInstances = {ViewModel, game.Players.LocalPlayer.Character}
local Mouse = BulletModule.getEndPos(1000,CastParams)
BulletModule.bullet(Player, ViewModel[CurrentGun].Barrel.Position, Mouse, gunConfig, true)--sentByOrigin = true
BulletHandle:FireServer(ViewModel[CurrentGun].Barrel.Position, Mouse, gunConfig, CurrentGun)
gunConfig.magAmmo -= 1
wait(gunConfig.fireDelay)
canFire = true
end
end
end)
--------------Start gun is prtimary incase
EquipGunViewModel(ViewModel ,LoadOut.primary.Name, Player, CurrentGun, "Primary")
gunConfig = require(ViewModel[LoadOut.primary.Name].Config)
CurrentAmmo = AmmoValues.PrimaryMag.Value
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isHoldingMouseButton1 = true
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = true
end
if input.KeyCode == Enum.KeyCode.One and CurrentGun ~= LoadOut.primary.Name then
EquipGunViewModel(ViewModel, LoadOut.primary.Name, Player, CurrentGun, "Primary")
CurrentGun = LoadOut.primary.Name
gunConfig = require(ViewModel[LoadOut.primary.Name].Config)
elseif input.KeyCode == Enum.KeyCode.Two and CurrentGun ~= LoadOut.secondary.Name then
EquipGunViewModel(ViewModel, LoadOut.secondary.Name, Player, CurrentGun, "Secondary")
CurrentGun = LoadOut.secondary.Name
gunConfig = require(ViewModel[LoadOut.secondary.Name].Config)
elseif input.KeyCode == Enum.KeyCode.Three and CurrentGun ~= LoadOut.melee.Name then
EquipGunViewModel(ViewModel, LoadOut.melee.Name, Player, CurrentGun, "Melee")
CurrentGun = LoadOut.melee.Name
gunConfig = require(ViewModel[LoadOut.melee.Name].Config)
elseif input.KeyCode == Enum.KeyCode.R then
if CurrentAmmo ~= gunConfig.MaxAmmo then
isReloading = true
ViewModel.Humanoid:LoadAnimation(ReplicatedStorage.Animations.ViewModel.Reload.M416):Play()
ReloadGunCharacter:FireServer(CurrentGun)
wait(gunConfig.ReloadDelay)
gunConfig.magAmmo = gunConfig.maxAmmo
GunGUI.Mag.Text = gunConfig.maxAmmo
isReloading = false
end
end
if input.KeyCode == Enum.KeyCode.Q then-- LEANİNG
if isLeaning == false then
leaningSide = "Left"
isLeaning = true
elseif isLeaning == true and leaningSide == "Left" then
isLeaning = false
end
elseif input.KeyCode == Enum.KeyCode.E then
end
end
end)
UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isHoldingMouseButton1 = false
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = false
end
end
end)
Vİdeo: as you can see the aiming is smooth but leaning doesnt even happen ? idk bruh
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.