Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make the arms face the way the camera is looking?

I've got my viewmodel working and all, but Its only facing one direction- It doesn't change when I face another direction. How would I do that? This is what I have currently:


local clone = game.Workspace.AWP:Clone()
clone.Parent = game.Workspace
game:GetService("RunService").RenderStepped:connect(function()
	print("ok")
	
	

	
		
	
	
		
	clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame.Position))
	
end)

and yes I have tried googling before coming here.

Thanks in advance.

3 comments

0

Connect not connect

0

On line 3, what you wrote may work in studio but could not work in a real game because camera is local to one player not the server.

0

You should probably get camera from a player

2 answers

✓ Accepted answer
 clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame))

The problem with this is it makes a new cframe (with default rotation) and simply sets it's position to that of the camera. Instead, try:

 clone:SetPrimaryPartCFrame(game.Workspace.Camera.CoordinateFrame)

However there's still an issue with this. This will only work in studio testing. Instead, I would simply do either of these..

If you wish for client side viewmodel with no one else seeing it, do this in a local script placed in StarterPlayerScripts.

local player = script.Parent.Parent
player.CharacterAdded:Connect(function(char) --detects when spawning each time
	local camera = game.Workspace.CurrentCamera
	local clone = game.Workspace.AWP:Clone() --Makes clone
	clone.Parent = game.Workspace
	game:GetService("RunService").RenderStepped:Connect(function()
		if clone then
			clone:SetPrimaryPartCFrame(game.Workspace.Camera.CoordinateFrame)
		end
	end)
end)

The reason that your viewmodel only points one direction is that you only change it's direction once. Add a loop on line 13:

while true do wait ()
clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame.Position))
end

This may work in studio, but in a real game camera cannot be accessed from the server.

EDIT: this won't fix all your problems because filtering enabled. Plus, a ROBLOX game works differently than a studio test in that it is multi player. I don't know what that would do to getting camera from workspace

This discussion is preserved as it was. New answers, comments, and votes are closed.