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

i am trying to make a viewmodel show on the players screen and its not how do i fix it?

i keep getting the error "Unable to assign property Position. Vector3 expected, got CFrame "

(i am bad at scripting)

and even if it got fixed i dont know if the viewmodel would show

heres my code:



local run = game:GetService("RunService")
local RS = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character
local GunModels = RS:WaitForChild("GunModels")
local GunModules = RS:WaitForChild("GunModules")
local Viewmodel = GunModels["DSA SA58 Viewmodel"]
--cloning the viewmodel
local clone = Viewmodel:Clone()
run.RenderStepped:Connect(function()
--changing parent
	clone.Parent = workspace
	--putting the viewmodel in front of players camera/head
	clone.PrimaryPart.Position = char.Head.CFrame * CFrame.new(-5.33, 0, 0)
end)

2 comments

0

thank you this really helped

0

If im correct the viewmodels parent needs to be the players camera. You can do this by defining the camera: local cam = workspace.CurrentCamera) and making that the clones parent!

1 answer

✓ Accepted answer

You put in Position, but you use CFrame. Hence the error. It's a really easy fix:

local run = game:GetService("RunService") local RS = game:GetService("ReplicatedStorage") local plr = game.Players.LocalPlayer local char = plr.Character local GunModels = RS:WaitForChild("GunModels") local GunModules = RS:WaitForChild("GunModules") local Viewmodel = GunModels["DSA SA58 Viewmodel"] --cloning the viewmodel local clone = Viewmodel:Clone() run.RenderStepped:Connect(function() --changing parent clone.Parent = workspace --putting the viewmodel in front of players camera/head clone.PrimaryPart.CFrame = char.Head.CFrame * CFrame.new(-5.33, 0, 0) end)

The only difference being I replace Position with CFrame on the second last line. Hope this helps!

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