Hello,
I have a problem with my script. When I try to lerp the gun into a new position, it will stay still. My print()'s are printing, but the actual lerp itself does nothing.
Heres my localscript, if you need the parenting just ask:
local GUI = game:GetService("StarterGui").Menu
local RepFirst = game.ReplicatedFirst
local RunService = game:GetService("RunService")
local Plr = game.Players.LocalPlayer
local Chr = Plr.CharacterAdded:Wait()
local CurrentCamera = game.Workspace.CurrentCamera
local Tool = script.Parent
local GunViewModel = RepFirst.Gun
local Mouse = Plr:GetMouse()
Tool.Equipped:Connect(function()
print("Equipped")
GunModel = GunViewModel:Clone()
GunModel.Parent = game.Workspace
local AimLerp = coroutine.create(function()
GunModel.Gun.CFrame = GunModel.Gun.CFrame:Lerp(GunModel.AimPart.CFrame,0.3)
end)
local EndAim = coroutine.create(function()
GunModel.Gun.CFrame = GunModel.Gun.CFrame:Lerp(GunModel.GunOrigin.CFrame,0.3)
end)
connection = RunService.RenderStepped:Connect(function(dt)
GunModel:SetPrimaryPartCFrame(CurrentCamera.CFrame)
end)
Mouse.Button2Down:Connect(function()
if Mouse then
coroutine.resume(AimLerp)
print("Aiming")
end
end)
Mouse.Button2Up:Connect(function()
if Mouse then
coroutine.close(AimLerp)
print("Not aiming")
coroutine.resume(EndAim)
end
end)
end)
Tool.Unequipped:Connect(function()
print("Unequipped")
wait()
connection:Disconnect()
GunModel:Destroy()
end)
Anything helps.