"CFrame expected, Got Instance" even though the target IS a CFrame

Yo,

Recently I’ve been working on some “FPS Framework” but I kept getting this error from the server script:
image

Server code:

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Shoot")

Remote.OnServerEvent:Connect(function(guy, position)
    local Speed = 500
    local Bullet = game.ReplicatedStorage.Projectiles.Bullet:Clone()
    Bullet.Parent = workspace
    Bullet.CFrame = position
    Bullet.Velocity = Bullet.CFrame.lookVector * Speed
end)

The main framework local script:

local guy = game.Players.LocalPlayer
local mouse = guy:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")
local TargetViewmodelName = script.Name
local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()
Viewmodel.Parent = workspace
local position
local HRP = Viewmodel:WaitForChild("HumanoidRootPart")

-- settings

local FOV = 90
-- local Projectile = "Default"

local function attachVM()
	HRP.CFrame = workspace.CurrentCamera.CFrame
	workspace.CurrentCamera.FieldOfView = FOV
	position = Viewmodel[script.Name].Handle.Attachment.CFrame
end

mouse.Button1Down:Connect(function(input)
	print("Pew")
	ReplicatedStorage.Remotes.Shoot:FireServer(guy, position)
end)

RunService.RenderStepped:Connect(attachVM)

My scripts are probably not ideal and their messy. I don’t care about that, I care more if I can get this working.
Thanks. :slight_smile:

2 Likes

The player who fired the event is passed in automatically, you only have ot pass in your other arguments

ReplicatedStorage.Remotes.Shoot:FireServer(position)

Passing it yourself sets it to the 2nd parameter, hence why it’s giving that error

3 Likes

That doesn’t relate to the error though… even if I get rid of that.

is the “Attachment” an Attachment instance?, if it’s I don’t think that has a CFrame I suggest using “Position”.

Does the same thing. Just replaces the CFrame in the error with Vector3

It does? Have you bothered printing it out. It’s also in the documentation for fire server, there is no need to do guy in the first parameter.

-- Include additional data when firing the event
remoteEvent:FireServer(BrickColor.Red(), Vector3.new(0, 25, 0))

So currently your remote function is returning 2 guys in the parameters because of the built in parameter.

Note that the connected function (lines 6-12) will receive the Player who fired the event as its first parameter ( player ), along with any additional parameters passed from the FireServer() call.

function(guy, guy2, position)

1 Like

Really? Doesn’t affect anything either way.

What error does it give when you do this instead?

ReplicatedStorage.Remotes.Shoot:FireServer(position)

I would do more print debugging if I were you. A good trick is using a variadic function to print all the parameters and make sure you are passing in variables in the proper order. Otherwise it’s your loss and your problem.

Remote.OnServerEvent:Connect(function(...)
print(...)
end)

The same error, and that was already what I used when I was told.

Alright so, the attachment didn’t move the position at all, but when making it a part it moves. I printed the position also and it DOES change.

Attachment depending on its parent has a different position, if u want the global position of it, I suggest getting the “WorldPosition” instead, basically if its parented to a part its “Position” can be Vector3.new(0,0,0) while its “WorldPosition” will be Vector3.new(-75.392, 0.5, 26.54)

I tried that already. Same stuff.

This text will be blurred

Hey everyone, I got it working but:


How could I fix this? New server code:

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Shoot")

Remote.OnServerEvent:Connect(function(guy, thingPos, mouseHit)

local Speed = 120

local Bullet = game.ReplicatedStorage.Projectiles.Bullet:Clone()

Bullet.Parent = workspace

--Bullet.Position = guy.Character.HumanoidRootPart.CFrame.lookVector

Bullet.CFrame = CFrame.new(mouseHit)

Bullet.Velocity = Bullet.CFrame.lookVector --* Speed

-- Bullet.Orientation = Vector3.new(0,-90,0)

end)

New local code:

local guy = game.Players.LocalPlayer

local mouse = guy:GetMouse()

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local UserInputService = game:GetService("UserInputService")

local RunService = game:GetService("RunService")

local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")

local TargetViewmodelName = script.Name

local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()

Viewmodel.Parent = workspace

local thingPos

local mouseHit

local HRP = Viewmodel:WaitForChild("HumanoidRootPart")

-- settings

local FOV = 90

-- local Projectile = "Default"

local function attachVM()

HRP.CFrame = workspace.CurrentCamera.CFrame

workspace.CurrentCamera.FieldOfView = FOV

thingPos = Viewmodel[script.Name].Handle.Fire.Position

mouseHit = mouse.Hit.lookVector

end

mouse.Button1Down:Connect(function(input)

print("Pew")

print(thingPos)

ReplicatedStorage.Remotes.Shoot:FireServer(guy, thingPos, mouseHit)

end)

RunService.RenderStepped:Connect(attachVM)

(not gonna bother getting this format correct)

Why are you still passing the guy variable? The first parameter will always pass the Player onto an OnServerEvent, you don’t need to reference it again

Also you should just be getting the mouse.Hit or mouse.Hit.Position of the mouseHit variable, no need to get its LookVector

local guy = game.Players.LocalPlayer
local mouse = guy:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")
local TargetViewmodelName = script.Name

local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()
Viewmodel.Parent = workspace

local thingPos
local mouseHit
local HRP = Viewmodel:WaitForChild("HumanoidRootPart")
-- settings
local FOV = 90
-- local Projectile = "Default"

local function attachVM()
    HRP.CFrame = workspace.CurrentCamera.CFrame
    workspace.CurrentCamera.FieldOfView = FOV
    thingPos = Viewmodel[script.Name].Handle.Fire.Position
    mouseHit = mouse.Hit.Position
end

mouse.Button1Down:Connect(function(input)
    print("Pew")
    print(thingPos)
    ReplicatedStorage.Remotes.Shoot:FireServer(thingPos, mouseHit)
end)

RunService.RenderStepped:Connect(attachVM)

You are still ignoring the person’s reply who explained the issue.

RemoteEvent:FireServer(arg1, arg2, arg3, ...)

Connects to:

RemoteEvent.OnServerEvent:Connect(
    function(playerFrom, arg1, arg2, arg3, ...)

    end
)

You aren’t handling the fact that an extra argument is added to the connection.

2 Likes

Yeaaah but uh… why is it going into the ground

Shouldn’t that be

Bullet.CFrame = CFrame.new(thingPos, mouseHit)

…?
Also the Velocity property is known to be deprecated, you might wanna use a BodyVelocity object instead to move the Bullet so that it can maintain a constant speed

1 Like

I didn’t know it was deprecated, woops.
But uh… now it faces only one way no matter the players direction. Something to do with lookvector?

Did you forget to multiply the speed of the Bullet?