Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
CMB1048 25
2 years ago

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)
0
thank you this really helped CMB1048 25 — 2y
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! xXmatthewgameingXx 2 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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!

Ad

Answer this question