-
What do you want to achieve?
my aiming dosnt work -
What is the issue?
it showsaimcf is not a valid member of Model "Workspace.Camera.Kar98K"
this is the script
local tool = script.Parent
local vm = game.ReplicatedStorage.Viewmodels.Kar98K:Clone()
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local SwayEffect = 1
local SwayCFrame = CFrame.new()
local LastCameraCFrame = CFrame.new()
local Walk = false
local WalkCFrame = CFrame.new()
local speed = hum.WalkSpeed/5
--sway and bobbing--
run.RenderStepped:Connect(function()
local Rotation = workspace.CurrentCamera.CFrame:toObjectSpace(LastCameraCFrame)
local X,Y,Z = Rotation:ToOrientation()
SwayCFrame = SwayCFrame:Lerp(CFrame.Angles(math.sin(X) * SwayEffect, math.sin(Y)* SwayEffect, 0), 0.25)
LastCameraCFrame = workspace.CurrentCamera.CFrame
vm:SetPrimaryPartCFrame(workspace.Camera.CFrame * WalkCFrame * CFrame.new(0,0,0) * SwayCFrame)
if Walk then
WalkCFrame = WalkCFrame:lerp(CFrame.new(0.03 * math.sin(tick() * (2.3 * speed)),0.03 * math.cos(tick() * (3 * speed)),0)*CFrame.Angles(0,0,-.02 * math.sin(tick() * (3 * speed))),.5)
else
WalkCFrame = WalkCFrame:lerp(CFrame.new(),.1)
end
end)
--check if the player is walking/running--
hum.Running:Connect(function(Speed)
if Speed >= 1 then
Walk = true
else
Walk = false
end
end)
--enable the viewmodel via equip--
tool.Equipped:Connect(function()
vm.Parent = workspace.Camera
end)
--disable the viewmodel via unequip
tool.Unequipped:Connect(function()
vm.Parent = game.Debris
end)
--disable the viewmodel via death--
hum.Died:Connect(function()
vm.Parent = game.Debris
end)
local UIS = game:GetService('UserInputService')
local Character = player.Character
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 24
sprint = true
local animationController = vm:WaitForChild("Controller")
local animation = vm.Sprint
local animationTrack = animationController:LoadAnimation(animation)
animationTrack:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
sprint = false
local animationController = vm:WaitForChild("Controller")
local animation = vm.SprintEnd
local bye = animationController:LoadAnimation(animation)
bye:Play()
end
end)
local maincf = CFrame.new()
local aimcf = CFrame.new()
local aiming = false
run.RenderStepped:Connect(function()
mouse.TargetFilter = cam
if vm then
vm:SetPrimaryPartCFrame(
cam.CFrame
* maincf
* aimcf
)
if aiming then
aiming = true
aimcf = aimcf:lerp(vm.aimcf, 0.1)
else
aiming = false
aimcf = aimcf:lerp(CFrame.new(), 0.1)
end
end
end)
mouse.Button2Down:Connect(function()
aiming = true
end)
mouse.Button2Up:Connect(function()
aiming = false
end)