Cframe value wont print correctly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m trying to get a player to teleport to “Picked_value”. (I have teleportation code in my script already)

  2. What is the issue?


print(CFrame.new(Vector3.new(picked_value)))    
    
    print(picked_value)

the first lines prints all 0’s and 1’s (I assume default C frames)

but the second print prints the assigned value to the variable

  1. What solutions have you tried so far? I tried asking around on discord, and also messed around with a few values, but doesn’t seem to fix anything.
1 Like

This probably means that your picked_value object isn’t being translated into a Vector3 correctly. Try doing print(Vector3.new(picked_value)) and see what happens. If your picked_value has coordinates, you may want to individually assign them to the vector.

Vector3.new(picked_value.X, picked_value.Y, picked_value.Z)

Or, if your picked_value is already a vector, don’t put Vector3.new() before it. A quick test in studio shows this:
image

2 Likes

I tried all of those and they come. back to 0. And I don’t understand what you meant in the last sentence.

1 Like

also to be more clear, picked_value is passed from a server script that picks and successfully prints the value.

1 Like

What is the exact value of picked_value?

1 Like

What I meant in the last sentence is that if pick_value is already a vector, you don’t have to put Vector3.new() before it because then it will make a new 0,0,0 vector which is what the screenshot was trying to show.

If your picked_value is already a vector, then your script would just be

CFrame.new(picked_value) instead of CFrame.new(Vector3.new(picked_value))

1 Like

the value changes (in the server script, it picked randomly from a table)

Also when I tried to print this as a CFrame I got this error

Is it already a CFrame? Where you do create picked_value?

2 Likes

Please show us the output of print(picked_value).

1 Like

this is the script I create the value in (Sorry for it being messy, I’m still new to scripting)

local Spawnloc1 = CFrame.new(64.65, 16105.011, -3289.95)
local Spawnloc2 = CFrame.new(114.65, 16105.011, -3289.95)
local Spawnloc3 = CFrame.new(164.65, 16105.011, -3289.95)
local Spawnloc4 = CFrame.new(214.65, 16105.011, -3289.95)

local Spawncords = {Spawnloc1, Spawnloc2, Spawnloc3, Spawnloc4}
print(Spawncords)

print(Spawncords[1])
print(Spawncords[2])
print(Spawncords[3])
print(Spawncords[4])


local value = math.random(1,#Spawncords) -- Get random number with 1 to length of table.
local picked_value = Spawncords[value] -- Pick value from table
print(picked_value)




local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local remoteEvent = ReplicatedStorage:WaitForChild("PlayerJoined")


local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player)

	print("A player has entered: " .. player.Name)
	print(picked_value)
	print("lmao")
	remoteEvent:FireClient(player, picked_value)

end)

this is the output (Variant depending on which number was picked out of the table)

It looks like your picked_value is already a CFrame then. You shouldn’t have to use CFrame.new() with it.

2 Likes

okay, so I saw that and realized that this should work

--Anchor head and stop player from moving
	repeat wait() until lplayer.Character
	local char = lplayer.Character
	local head = char:WaitForChild('Head')
	char.HumanoidRootPart.CFrame = picked_value
	
	print(picked_value)
	head.Anchored = true
	print("Your head should be anchored")
	local humanoid = char.Humanoid
	humanoid.WalkSpeed = 0

end

-- Call "onNotifyPlayer()" when the server fires the remote event
remoteEvent.OnClientEvent:Connect(onfreezeplayer)

but it just makes my character spawn at the world origin rather than teleporting them to the correct location (to the Cframe)

local value = math.random(1,#Spawncords) -- Get random number with 1 to length of table.
local picked_value = Spawncords[value] -- Pick value from table
print(picked_value)

Move this inside of PlayerAdded so that it runs every time a new player joins. To be clear though, this means that each player gets assigned a spawnpoint when they join, and they will always spawn at that location.

Can I see the full script from your most recent post?

1 Like

thank you, and which script are you referring to? If it’s the one that I made the original post about, then this is it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("PlayerJoined")

-- Ignore the passed player; start with additional passed data
local function onfreezeplayer(picked_value)
	print(picked_value)
	print("lmao")
	local lplayer = game.Players.LocalPlayer
	print(lplayer)
	local spawnbox = CFrame.new(179.5, 16108.009, -3258.5)
	lplayer:RequestStreamAroundAsync(spawnbox.Position)
	print("Picked value:")
	print(picked_value)
	print("Incoming server event...")
	
	picked_value = picked_value
--change cam
	local Players = game:GetService("Players")
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	local WFC = game.ReplicatedStorage:WaitForChild("SB1cam")
	camera.CFrame = game.ReplicatedStorage.SB1cam.CFrame

--Anchor head and stop player from moving
	repeat wait() until lplayer.Character
	local char = lplayer.Character
	local head = char:WaitForChild('Head')
	char.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(picked_value))
	print("devforum info")
	print(char.HumanoidRootPart.CFrame)
	print("^char")
	print(CFrame.new(Vector3.new(picked_value)))
	print("^Cframe.vector")
	print((Vector3.new(picked_value)))
	print("vec3")
	print(CFrame.new(picked_value))
	print("^Cfram.new")
	print(picked_value)
	head.Anchored = true
	print("Your head should be anchored")
	local humanoid = char.Humanoid
	humanoid.WalkSpeed = 0

end

-- Call "onNotifyPlayer()" when the server fires the remote event
remoteEvent.OnClientEvent:Connect(onfreezeplayer)

ignore any random prints lol, those are just there for personal reference.

If you want a vector value, use math.rad() it converts vector values into cframes because cframes are very complicated in their numbers.

1 Like

I tried this as well, but once again it errors to even print it

Did u use it like this? CFrame.new(math.rad(number),0,0)
Also, I see many errors, cframes cannot take vector values

You wouldn’t convert to radians if you are using the position part of the CFrame. And CFrame.new absolutely can use a Vector3.

@mcox6 when is this supposed to teleport the player to the spawns? Whever the character loads? Or is it supposed to be conditional on the ‘freezeplayer’ deal or something like that?

when the player loads in, it teleports them to what I call a “Spawn box” That’s where they can customize their player, before fully spawning onto the map.