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

CFrame.new not adding inside the "equation"?[Solved]

Asked by 9 years ago

It now teleports the player to the location, with an added Vector3 of (0, 2, 0) here is my script


repeat wait(1) if workspace:findFirstChild("Player") then if script.Parent.Value == 1 and script.Parent.Parent.CamValue.Value == 1 then script.Parent.Parent.MechName.Text = "Forest Camo Mech single gun" Workspace.CurrentCamera.CameraSubject = Workspace.CameraFocus1 Workspace.CurrentCamera.CameraType = "Attach" wait(0.75) Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Map.Spawners.WhiteSpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 2 and script.Parent.Parent.CamValue.Value == 1 then script.Parent.Parent.MechName.Text = "Forest Camo Mech double guns" Workspace.CurrentCamera.CameraSubject = Workspace.CameraFocus2 wait(0.75) Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Map.Spawners.GraySpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 3 and script.Parent.Parent.CamValue.Value == 1 then script.Parent.Parent.MechName.Text = "Forest Camo Mech double guns w/ cannon" Workspace.CurrentCamera.CameraSubject = Workspace.CameraFocus3 wait(0.75) Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Map.Spawners.BlackSpawn.Position + Vector3.new(0, 2, 0)) end end until script.Parent.Parent.CamValue.Value == 0

Please help!!! Thank you!!!

0
I lost a point? Seriously? Why? yogipanda123 120 — 9y
1
Don't move your Humanoid. Rather, move the Torso using CFrame; or the model using :MoveTo() or :SetPrimaryPartCFrame() Redbullusa 1580 — 9y
0
If i move the torso will the rest of the player go with it? yogipanda123 120 — 9y
1
If you use CFrame, yes. If you use Position, it will only move the torso and will kill the player. Spongocardo 1991 — 9y
View all comments (2 more)
0
K, thank you, another problem was i was adding CFrames, not Vector3s yogipanda123 120 — 9y
0
@yogi I think you lost a point because your original title was bad. yumtaste 476 — 9y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Naming notes: ROBLOX prefer workspace (lowercase) and FindFirstChild (uppercase)


First of all, tab your code correctly. The next remark is that script.Parent.Parent.CamValue.Value == 1 is repeated in every condition, so you should probably just wrap the whole thing in an if.

repeat
    wait(1)
    if workspace:FindFirstChild("Player") and script.Parent.Parent.CamValue.Value == 1 then
        if script.Parent.Value == 1 then
            script.Parent.Parent.MechName.Text = "Forest Camo Mech single gun"
            workspace.CurrentCamera.CameraSubject = workspace.CameraFocus1
            workspace.CurrentCamera.CameraType = "Attach"
            wait(0.75)
            workspace.Player.Torso.CFrame = (CFrame.new(workspace.Map.Spawners.WhiteSpawn.Position + CFrame.new(0, 2, 0)))
        elseif script.Parent.Value == 2 then
            script.Parent.Parent.MechName.Text = "Forest Camo Mech double guns"
            workspace.CurrentCamera.CameraSubject = workspace.CameraFocus2
            wait(0.75)
            workspace.Player.Torso.CFrame = (CFrame.new(workspace.Map.Spawners.GraySpawn.Position + CFrame.new(0, 2, 0)))
        elseif script.Parent.Value == 3 then
            script.Parent.Parent.MechName.Text = "Forest Camo Mech double guns w/ cannon"
            workspace.CurrentCamera.CameraSubject = workspace.CameraFocus3
            wait(0.75)
            workspace.Player.Torso.CFrame = (CFrame.new(workspace.Map.Spawners.BlackSpawn.Position + CFrame.new(0, 2, 0)))
        end
    end
until script.Parent.Parent.CamValue.Value == 0


As to the actual problem:

You cannot do Vector3 + CFrame; .Position is a Vector3 and CFrame.new makes a CFrame.

The solution would be to flip them; but I would argue it makes more sense to use

workspace.Player.Torso.CFrame = workspace.Map.Spawners.BlackSpawn.CFrame + Vector3.new(0, 2, 0)
-- etc

These lines of code are very long. You should probably make variables to clean it up. For instance...

repeat
    wait(1)
    if workspace:FindFirstChild("Player") and script.Parent.Parent.CamValue.Value == 1 then
        local spot -- The part we are moving the player to.
        local focus -- The part we are focusing the camera on
        local message -- The text to show
        workspace.CurrentCamera.CameraType = "Attach"
        if script.Parent.Value == 1 then
            text = "Forest Camo Mech single gun"
            focus = workspace.CameraFocus1
            spot = workspace.Map.Spawners.WhiteSpawn
        elseif script.Parent.Value == 2 then
            text = "Forest Camo Mech double guns"
            focus = workspace.CameraFocus2
            spot = workspace.Map.Spawners.GraySpawn
        elseif script.Parent.Value == 3 then
            text = "Forest Camo Mech double guns w/ cannon"
            focus = workspace.CameraFocus3
            spot = workspace.Map.Spawners.BlackSpawn
        end
        script.Parent.Parent.MechName.Text = text
        workspace.CurrentCamera.CameraSubject = focus
        wait(0.75)
        workspace.Player.Torso.CFrame = spot.CFrame + Vector3.new(0, 2, 0)
    end
until script.Parent.Parent.CamValue.Value == 0

Note that if you're using CamValue only at 0 and 1, you should just use BoolValue instead.

Ad

Answer this question