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

Unable to cast Vector3 to CoordinateFrame With Camera?

Asked by 4 years ago

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

0
Before you ask the module script just has gun settings like RPM, Mag size and Spare ammo RecycleBicycle 60 — 4y
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 Block_manvn 395 — 4y
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 RecycleBicycle 60 — 4y
0
edit: not experienced! RecycleBicycle 60 — 4y
View all comments (6 more)
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! Block_manvn 395 — 4y
0
Thanks mate RecycleBicycle 60 — 4y
0
Ill try this out RecycleBicycle 60 — 4y
0
Error: 10:12:46.981 - attempt to multiply a Vector3 with an incompatible value type or nil RecycleBicycle 60 — 4y
0
Do you make the variable first? Block_manvn 395 — 4y
0
variable? RecycleBicycle 60 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
It helped but the model is not in the camera RecycleBicycle 60 — 4y
Ad

Answer this question