#bag with gun script and viewmodel script

1 messages · Page 1 of 1 (latest)

echo lance
#

what to do if after death the weapon and ViewModel are bugged

#
local lastUnequipTime = 0
local delayDuration = 1

tool.Equipped:Connect(function()

    isEquipped=true
    
    local currentTime = tick()
    
    if currentTime - lastUnequipTime >= delayDuration then
        canShoot = true
    else
        canShoot = false
        delay(delayDuration - (currentTime - lastUnequipTime), function()
            canShoot = true
        end)
    end

    player.CameraMode=Enum.CameraMode.LockFirstPerson
    GUI.Text = ammoInClip.. "/8"

    mouse.Icon="rbxassetid://93245173888757"

    if isZoomed then 
        camera.FieldOfView=80
        isZoomed=false
        setMouseSensitivity(originalSensitivity)
    end
    tool.Kobur:Play()

end)

tool.Unequipped:Connect(function()
    
    isEquipped=false
    
    lastUnequipTime = tick()
    canShoot = false
        
    player.CameraMode=Enum.CameraMode.Classic    
    GUI.Text = "-/-"

    mouse.Icon=""

    if isZoomed then 
        camera.FieldOfView=80
        isZoomed=false
        setMouseSensitivity(originalSensitivity)
    end

    tool.Kobur:Play()

end)

humanoid.Died:Connect(function()
    tool:Destroy()
end)
#

this local script for shoot and reload

#
tool.Equipped:Connect(function()
    if humanoid.JumpHeight == 0 then return end
    if humanoid.WalkSpeed == 0 then return end
    equipped = true
    
    -- Клонируем ViewModel
    game.ReplicatedStorage:WaitForChild("ViewModelPM"):Clone().Parent = Camera

    local viewmodel = Camera:FindFirstChild("ViewModelPM")

    if viewmodel then
        animatorVM = viewmodel.StarterHumanoid.Animator
    end

    -- Получаем анимации
    local walkanim = ReplicatedStorage.Animations.WalkPM
    local runanim = ReplicatedStorage.Animations.RunPM
    local aimanim = ReplicatedStorage.Animations.AimPM
    local aimidle = ReplicatedStorage.Animations.AimIdlePM


    -- Загружаем анимации
    walkAnimTrack = animatorVM:LoadAnimation(walkanim)
    runAnimTrack = animatorVM:LoadAnimation(runanim)
    aimAnimTrack = animatorVM:LoadAnimation(aimanim)
    idleAnimTrack = animatorVM:LoadAnimation(aimidle)


    -- Цикличность
    aimAnimTrack.Looped = false
    idleAnimTrack.Looped = true
    
    aimAnimTrack.Priority = Enum.AnimationPriority.Action
    idleAnimTrack.Priority = Enum.AnimationPriority.Action
    
end)

tool.Unequipped:Connect(function()
    equipped = false
    if Camera:FindFirstChild("ViewModelPM") then
        Camera.ViewModelPM:Destroy()
    end
    if walkAnimTrack and walkAnimTrack.IsPlaying then walkAnimTrack:Stop() end
    if runAnimTrack and runAnimTrack.IsPlaying then runAnimTrack:Stop() end
    if aimAnimTrack and aimAnimTrack.IsPlaying then aimAnimTrack:Stop() end
    if idleAnimTrack and idleAnimTrack.IsPlaying then idleAnimTrack:Stop() end
    isaim = false
end)
#

this local script for viewmodel, but after death dont work

coarse vector
#

What

stiff terrace
#

idk but maybe its bc ur destroying it in a local script