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

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

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!!!

6 comments

0

I lost a point? Seriously? Why?

1

Don't move your Humanoid. Rather, move the Torso using CFrame; or the model using :MoveTo() or :SetPrimaryPartCFrame()

0

If i move the torso will the rest of the player go with it?

1

If you use CFrame, yes. If you use Position, it will only move the torso and will kill the player.

0

K, thank you, another problem was i was adding CFrames, not Vector3s

0

@yogi I think you lost a point because your original title was bad.

1 answer

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.

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