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

bad argument #3 to 'CFrame' (CFrame expected, got Vector3), how can I fix it?

Asked by
enes223 327 Moderation Voter
5 years ago

Im trying to make a camping game with tent but when I try to make tent it gives this error (on title), how can I fix it?

LocalScript code: --By enes223

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local torso = char:WaitForChild("Torso")

local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("BuildTent")
local Remote2 = RS:WaitForChild("BuildMegaTent")

script.Parent.MouseButton1Click:Connect(function()
if plr.Values.TentLevel.Value == 1 or 2 then
local position = torso.Position
script.Parent.Visible = false
Remote:FireServer(position)
elseif plr.Values.TentLevel.Value == 3 then
local position = torso.CFrame.lookVector + Vector3.new(0,0,10) * 0
Remote2:FireServer(position)
end
end)

ServerScript code:

BuildTent.OnServerEvent:connect(function(plr,position)
local tent = SS:WaitForChild("Tent")
local clone = tent:Clone()
clone.Parent = game.Workspace
clone.Name = plr.Name.."'s Tent"
clone.TentMesh.CFrame = position
clone.TentMesh1.CFrame = position
end)
0
CFrame.new(position) theking48989987 2147 — 5y
0
This is also an option I forgot to mention. BlueGrovyle 278 — 5y

1 answer

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

You cannot set a CFrame to a Vector3 value, as you do in your server script. Instead, you need to set the CFrame values of "TentMesh" and "TentMesh1" to the torso's CFrame, not it's position. To fix your error, just change the parameter you pass to the remote event to the torso's CFrame instead of it's position:

Remote:FireServer(torso.CFrame)

Another catch: Your logic on the if statement in your local script is incorrect. You have:

if  plr.Values.TentLevel.Value ==  1  or  2  then

Whereas you should have:

if plr.Values.TentLevel.Value == 1 or plr.Values..TentLevel.Value == 2 then

The individual statements that create a compound if statement should be able to stand alone as separate if statements. In your example, if they were separated (in terms of English) into separate if statements, it would essentially look like this: "if value == 1 or if 2 then ..." That doesn't make any sense. The computer will interpret the second statement as, "if 2 is not nil then" which is definitely not what you want, because it's always true, therefore making your compound statement always true. If you do my corrected version, it now properly looks like this: "if value == 1 or if value == 2 then ..."

Ad

Answer this question