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

Unable to cast Vector3 to CoordinateFrame With Camera?

Yeah, I'm in a pickle. Doing fps framework is hard and I only began to do testing with a test script and got this error now I'm confused at this point.

-- Variables
local PLR = game.Players.LocalPlayer
local runS = game:GetService("RunService")
local Camera = workspace.CurrentCamera

-- Gun setup
local gun = game.ReplicatedFirst.Guns.UMP45:Clone()
local Settings = require(game.ReplicatedStorage.GunModules[gun.Name])
local WeaponPos = Vector3.new(0,-0.5,0)

-- Loads run service
runS.RenderStepped:Connect(function()
	gun:SetPrimaryPartCFrame(CFrame.new() * WeaponPos)
end)

gun.Parent = Camera
local idle = gun.Humanoid:LoadAnimation(game.ReplicatedStorage.GunModules[gun.Name].Animations.Idle)
idle:Play()

Any help is needed

10 comments

0

Before you ask the module script just has gun settings like RPM, Mag size and Spare ammo

0

CFrame.Position will return Vector3, so you can do CFrame.Position = Vector3 to cast CFrame to Vector3 and vice versa. Credit to @TheDeadlyPanther ;) https://scriptinghelpers.org/questions/25247/vector3-and-cframe-conversion

0

@Block_manvn can you give me an example of how can it be used so I don't mess up as I'm an experienced coder

0

edit: not experienced!

0

In line 13, do like this instead gun:SetPrimaryPartCFrame(cframe.Position * WeaponPos) --make a variable of CFrame.new() first                                                                                  Note: Im not experienced coder!

0

Thanks mate

0

Ill try this out

0

Error: 10:12:46.981 - attempt to multiply a Vector3 with an incompatible value type or nil

0

Do you make the variable first?

0

variable?

1 answer

The problem here is that when you multiply a CFrame by a Vector3 you get a Vector3 (not sure though) So instead of gun:SetPrimaryPartCFrame(CFrame.new()*WeaponPos) do gun:SetPrimaryPartCFrame(CFrame.new(CFrame.new()*WeaponPos)) that is confusing, since you're multiplying an empty cframe by a vector you can just cast it directly. So do this

-- Variables
local PLR = game.Players.LocalPlayer
local runS = game:GetService("RunService")
local Camera = workspace.CurrentCamera

-- Gun setup
local gun = game.ReplicatedFirst.Guns.UMP45:Clone()
local Settings = require(game.ReplicatedStorage.GunModules[gun.Name])
local WeaponPos = Vector3.new(0,-0.5,0)

-- Loads run service
runS.RenderStepped:Connect(function()
    gun:SetPrimaryPartCFrame(CFrame.new(WeaponPos))
end)

gun.Parent = Camera
local idle = gun.Humanoid:LoadAnimation(game.ReplicatedStorage.GunModules[gun.Name].Animations.Idle)
idle:Play()

If this helped, mark this as the answer!

1 comment

0

It helped but the model is not in the camera

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