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

How do I code C-Frame to get player position?

I'm making a time stop script for a game I'm working on and need help with C-Framing. I have an Idea as to how to plan it out but not how to do it. How would I code C-Frame position so that it grabs the character's position and adds it to the C-Frame position code?

here the code if it helps:

if orb then
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:wait()
	orb.Shape = "Cylinder"
	orb.Material = "Neon"
	local weld = Instance.new("WeldConstraint")
	weld.Parent = workspace
	weld.Part0 = orb
	weld.Part1 = character.HumanoidRootPart
	orb.Position = Vector3.new (106.59,16.5,-111.73) -- Where to add players position, however these coords are preset to a random location since i couldn't figure out how to get Player Position.

1 comment

0

Tbh, when freezing the player its just best to anchor their parts, also, you're creating stuff from the client, making it only replicate to the client and not the server seeing you used LocalPlayer 

3 answers

✓ Accepted answer

Hope this helps:

if orb then
    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:wait()
    orb.Shape = "Cylinder"
    orb.Material = "Neon"
    local weld = Instance.new("WeldConstraint")
    weld.Parent = workspace
    weld.Part0 = orb
    weld.Part1 = character.HumanoidRootPart
    if player.Character:FindFirstChild("Torso") == nil then --checks to see if player is r15
        orb.Position = Vector3.new (player.Character.LowerTorso.Position.X,player.Character.LowerTorso.Position.Y,player.Character.LowerTorso.Position.Z)
    else --this is what happens if r6
        orb.Position = Vector3.new (player.Character.Torso.Position.X,player.Character.Torso.Position.Y,player.Character.Torso.Position.Z)
    end
end

First of all, you would want to do this in a server side script. Else the teleportation will only affect the client. To get the player position, simply use:

if charactert then
	orb.CFrame = CFrame.new(character.Position)
end

Hope this helped! ????

2 comments

0

I meant to put an emoji, not question marks.

0

Sort of; I see where you are going with the character.Position but when I run the script, I get error 13:24:08.385 - ServerScriptService.BeamSummonEmit:2: attempt to index nil with 'Character'. Is there any way to get around this? I've heard that the character isnt seen serverside.

if orb then
    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:wait()
    orb.Shape = "Cylinder"
    orb.Material = "Neon"
    local weld = Instance.new("WeldConstraint")
    weld.Parent = workspace
    weld.Part0 = orb
    weld.Part1 = character.HumanoidRootPart
    orb.Position = Vector3.new(player.Character.Torso.Position) -- Get the position of the torso of the local player
end

1 comment

0

For some reason, the part spawns at the map Origin... How could i fix this?

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