Categories > Coding > Lua >

Get Plr's CFrame Script Stopped Working (KRNL)

Posts: 3

Threads: 2

Joined: Mar, 2023

Reputation: 0

Posted

I made a post a while ago about getting a players CFrame and writing it to a file, but after trying to modify it, it didnt work, I reverted it back to its original state and still it isnt working. I just need this code to get all the players body parts CFrame and write it to a file that can be used in studio (can be read as a table and put on a dummy for example) in a modular way so I can change what objects it records

Original Code:
local ply = game:GetService("Players").LocalPlayer
local char = ply.Character or ply.CharacterAdded:Wait()
local root = char.PrimaryPart or char:WaitForChild("HumanoidRootPart")

local function truncate(x)
    -- Fixes formatting as -0 which makes no sense + truncates the number for
    -- that range (shouldnt matter much) also truncates to 2 decimal places
    x = x < 0.01 and x > -0.01 and 0 or x
    x = math.floor(x * 100) / 100
    return x
end

local function truncateMany(...)
    local args = {...}
    for i = 1, select("#", ...) do
        args[i] = truncate(args[i])
    end
    return unpack(args)
end

local function formatCoordinateFrame(cf)
    -- Get the position and angle
    local px, py, pz = truncateMany(cf.X, cf.Y, cf.Z)
    local ax, ay, az = truncateMany(cf:ToEulerAnglesXYZ())

    -- %.2f formats a float to a number with 2 decimal places. I use math.deg
    -- so you can read the angle in degrees which is easier imo
    local pos = string.format("CFrame.new(%.2f, %.2f, %.2f)", px, py, pz)
    local ang = string.format("CFrame.Angles(math.rad(%.2f), math.rad(%.2f) math.rad(%.2f))",
        math.deg(ax), math.deg(ay), math.deg(az))

    -- Doesn't need formatting because no angle
    if ax == 0 and ay == 0 and az == 0 then
        return pos
    end

    -- Return the formatted string with angle
    return pos.." * "..ang
end

writefile("position.txt", formatCoordinateFrame(root.CFrame))

  • 0

yvneEnvy

<><><<>>><<>

Posts: 306

Threads: 47

Joined: Mar, 2023

Reputation: 3

Replied

  • 0

Posts: 8

Threads: 0

Joined: Apr, 2023

Reputation: 0

Replied

Surely you only know New York as a place of America, right? But now there is one more great game genre that you should experience: nytimes crossword

 

  • 0

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )