Gun disappear after few seconds when eqquiped

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am following a ViewModel tutorial made by @rokoblox5 (Link). When I finished it, I found the problem as said as the title. I don’t why is it like that.

  2. What is the issue? Include screenshots / videos if possible!
    Just like the title said, “Gun disappear after few seconds when equipped”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I already look for the solution in Devforum, “Tool Disappear after equipped”. But it doesn’t help me. I don’t know if it is the script’s problem.

Here are the scripts:

Local Script (Tool):

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character  or Player.CharacterAdded:Wait()
if not Character.Parent then
	Character = Player.CharacterAdded:Wait()
end
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")

local Animation = Instance.new("Animation", script.Parent)
Animation.AnimationId = "rbxassetid://11366011046"
Animation = Animator:LoadAnimation(Animation)
Animation:SetAttribute("ViewModelAnimation", true)

script.Parent.Equipped:Connect(function()
	Animation:Play()
end)

script.Parent.Unequipped:Connect(function()
	Animation:Stop()
end)

Local Script (StarterCharacterScript):

local RunService = game:GetService("RunService")
local PhysicsService = game:GetService("PhysicsService")

local Camera = workspace.CurrentCamera
if Camera:FindFirstChild("ViewModel") then
	Camera.ViewModel:Destroy()
end

local Character = script.Parent
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")

Character.Archivable = true
local ViewModel = Character:Clone()
ViewModel.Parent = Camera
ViewModel.Name = "ViewModel"
Character.Archivable = false

local ViewModelAnimator = ViewModel.Humanoid.Animator
ViewModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ViewModel.Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
ViewModel.Humanoid.BreakJointsOnDeath = false

ViewModel.Head.Anchored = true
ViewModel.PrimaryPart = ViewModel.Head
ViewModel:SetPrimaryPartCFrame(CFrame.new(0,5,10))

for _, part in pairs(ViewModel:GetDescendants()) do
	if part:IsA("BasePart") then
		part.CastShadow = false
		PhysicsService:SetPartCollisionGroup(part, "ViewModel")
		
		local LowerName = part.Name:lower()
		if LowerName:match("leg") or LowerName:match("foot") then
			part:Destroy()
		elseif not (LowerName:match("arm") or LowerName:match("hand")) then
			part.Transparency = 1
		end
	elseif part:IsA("Decal") then
		part:Destroy()
	elseif part:IsA("Accessory") then
		part:Destroy()
	elseif part:IsA("LocalScript") then
		part:Destroy()
	end
end

local LoadedAnimatons = {}
Animator.AnimationPlayed:Connect(function(animationTrack)
	if animationTrack:GetAttribute("ViewModelAnimation") == false then
		return
	end

	if not LoadedAnimatons[animationTrack] then
		LoadedAnimatons[animationTrack] = ViewModelAnimator:LoadAnimation(animationTrack.Animation)
	end
end)

local function UpdateAnimations()
	for CharAnim, Anim in pairs(LoadedAnimatons) do
		if CharAnim.IsPlaying ~= Anim.IsPlaying then
			if CharAnim.IsPlaying then
				Anim:Play()
			else
				Anim:Stop()
			end
		end
		
		Anim.TimePosition = CharAnim.TimePosition
		Anim:AdjustWeight(CharAnim.WeightCurrent, 0)
	end
end

Character.DescendantAdded:Connect(function(Obj)
	if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
		task.wait()
		Obj.Part0 = ViewModel[Obj.Part0.Name]
	end
end)

RunService.RenderStepped:Connect(function(deltaTime)
	UpdateAnimations()
	ViewModel:SetPrimaryPartCFrame(Camera.CFrame)
	
	local ViewModelShirt = ViewModel:FindFirstChildWhichIsA("Shirt") or Instance.new("Shirt", ViewModel) -- // Create a shirt if there is no shirt found.
	local CharacterShirt = Character:FindFirstChildWhichIsA("Shirt")
	if CharacterShirt then
		-- // If a shirt was found in the player's character, then set the ViewModel's shirt to the same shirt.
		ViewModelShirt.ShirtTemplate = CharacterShirt.ShirtTemplate
	end

	for _, Part in pairs(ViewModel:GetChildren()) do
		if Part:IsA("BasePart") then
			-- // Set the color of each part of the ViewModel to the color of the part with same name in the character.
			Part.Color = Character[Part.Name].Color
		end
	end
end)

I wish someone can help me solve this problem. Besides, the FPS zombie game is one of my favourite games to play. So, I wish I can make one too.

Thank you!

This isn’t constructive enough. Yes, you’ve identified the problem, but we don’t know how the issue plays out.

Don’t simply depend on the title. Please provide more details by sending a screenshot or video about the problem, or at least tell us the issue in detail (e.g. Does the weapon fall off the hand? Does the Script emit errors in the output [If so, what does it say]? How is the weapon set up [in Explorer]?)

Right now, I do not see any issue related to your problem with the Scripts.

The gun just gone to nowhere.
Like not exist in the game.
30303030030303030303

My guess is that you still have not changed the name of the main gun’s handle to “Handle”? Tools would usually require a Part named “Handle” to properly snap onto a player’s hand. Without a “Handle”, the Tool won’t snap to the hand, and may instead fall down the world if it is untouchable (CanCollide = false).

1 Like

Like this?
image
3030300000000000000000

Yes. It should now work. The gun may be oriented or positioned incorrectly, in which you should try adjusting the GripForward, GripRight, and GripUp properties.

Personally, I have never used them, so go check them out in the Roblox documentation site: Tool | Roblox Creator Documentation


but it still didn’t work

Can you send a video of how the gun disappears?

1 Like

Alright, I rechecked the code. This in particular looks incorrect:

Character.DescendantAdded:Connect(function(Obj)
	if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
		task.wait()
		Obj.Part0 = ViewModel[Obj.Part0.Name]
	end
end)

I’ve seen one DevForum post, which may have a similar issue. Try duplicating the weapon instead to the ViewModel, and weld that clone to the ViewModel’s hand, maybe?

How do I write the code?

30303030303030030303

Character.DescendantAdded:Connect(function(Obj)
	if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
		local NewGrip = Obj:Clone()
		local TargetPart = Obj.Part1:Clone()
		local NewParent = ViewModel[Obj.Part0.Name]
		
		Obj.Parent = NewParent
		TargetPart = ViewModel
		
		Obj.Part0 = NewParent
		Obj.Part1 = TargetPart
	end
end)

This isn’t tested. Let me know if it works or not.

1 Like

Roblox Keep broken ugh! :confused:


303030303

drag the game tab out might fix it
if the view is invis

1 Like

image
It’s not working + the gun is still disappearing

I tried. Eventually, I go do the Roblox Studio registry method and I think it works.

I may have forgotten to add TargetPart.Parent = ViewModel.

Character.DescendantAdded:Connect(function(Obj)
	if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
		local NewGrip = Obj:Clone()
		local TargetPart = Obj.Part1:Clone()
		local NewParent = ViewModel[Obj.Part0.Name]
		
		Obj.Parent = NewParent
		TargetPart.Parent = ViewModel
		
		Obj.Part0 = NewParent
		Obj.Part1 = TargetPart
	end
end)

About the gun problem, I have run out of ideas. Sorry about that.

1 Like

instead of task.wait() use wait()

Character.DescendantAdded:Connect(function(Obj)
	if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
		wait()
		Obj.Part0 = ViewModel[Obj.Part0.Name]
	end
end)

task.wait() is a new, and faster version of wait().


303030000000000000000000000000000