Strange Viewmodel Bug

  1. I’m atempting to make a basic tool system with a viewmodel.

  2. For what ever reason when I tried to create a part that removed the tool and the viewmodel i’d get this strange error viewmodel is not a member of the camera even though it is.

-- Here is a example 

  1. I’ve tried fixing it with wait for child a multitude of tutorials and even looking for it on devfourms and found nothing. Thanks in advance! :smile:

Heres the script that I used for the removal part

-- Im the script
local player = game.Players.LocalPlayer
local Camera = game.workspace.CurrentCamera
local ViewModel
script.Parent.Triggered:Connect(function(player)
	
	local Hand = player.Character

	local item = Hand:FindFirstChild("TeddyBear :D")
	if item then
		ViewModel = Camera.ViewModel
		ViewModel:Destroy()
		item:Destroy()		
	end
end)

1 Like

try doing

ViewModel = Camera:FindFirstChild("ViewModel")
if ViewModel then
blah blah blah
end

unfortunately it didn’t work… :thinking: Heres a video example


It deleted the tool but not the viewmodel, the viewmodel is still a child of camera btw.

-- Heres the new code I made using your example
local player = game.Players.LocalPlayer
local ViewModel
script.Parent.Triggered:Connect(function(player)
	
	local Hand = player.Character

	local item = Hand:FindFirstChild("TeddyBear :D")
	if item then
		
		item:Destroy()		
	end
	
	local Camera = workspace.CurrentCamera
	
	ViewModel = Camera:FindFirstChild("ViewModel")
	if ViewModel then
		ViewModel:Destroy()
	end
	
end)
1 Like

I get this error too now randmly never happened before, my code also still runs afeter the error.

I’m guessing it’s a Roblox bug. It sure is annoying, I can wrap it in aa pcall even though that’s less effiecent for my code.

1 Like

i’m also having a mysterious bug going on with my tool dev products so I have a feeling its related to Roblox right now.

That error is on the server. There is no ViewModel on the server.

The ViewModel only exists on the client.

1 Like

Would you happen to know how to fix it? the game im making is singal player and i’m not a very good scripter. thanks in advanced :sweat_smile: