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

Why is this happening with my pseudo character?

Asked by
novipak 70
9 years ago

So I've started to work on a very basic pseudo character. I nearly got it to "work" (spawn in a couple bricks welded together that would stay there), however I was told that I had to check AutoCharacterLoads to false. However, now there is no character (neither the default, nor the pseudo character), and my camera is where my pseudo character should've spawned. I would greatly appreciate any help. Thanks.

Here's my code, it is in StarterGui:

local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
cam.CameraType = "Scriptable"

if not workspace:FindFirstChild('Players') then
        m = Instance.new('Model',workspace)
        m.Name = 'Players'
end

function spawn_pseudo_character(player)
        if workspace.Players:FindFirstChild(player.Name) then -- character already exists, don't do it again
                return
        end
        print('Building character')
    local char = Instance.new("Model", workspace.Players)
    char.Name = player.Name

    local head = Instance.new("Part")
    head.Name = "Head"
    head.Anchored, head.Locked, head.CanCollide = false, true, true
    head.Transparency = 0
    head.FormFactor = "Symmetric"
    head.Size = Vector3.new(1,1,1)
    head.TopSurface, head.BottomSurface = "Smooth", "Smooth"
    head.CFrame = CFrame.new(0, 11.5, 0)
    head.Parent = char

    local torso = Instance.new("Part")
    torso.Name = "Torso"
    torso.Anchored, head.Locked, head.CanCollide = false, true, true
    torso.Transparency = 0
    torso.FormFactor = "Symmetric"
    torso.Size = Vector3.new(1,2,1)
    torso.TopSurface, head.BottomSurface = "Smooth", "Smooth"
    torso.CFrame = CFrame.new(0, 10, 0)
    torso.Parent = char

    local neck = Instance.new("Weld")
    neck.Name = "Neck"
    neck.Part0, neck.Part1 = torso, head
    neck.C0, neck.C1 = torso.CFrame:inverse(), head.CFrame:inverse()
    neck.Parent = torso

        print('Built character')

    local hum = Instance.new("Humanoid", char)

        player.Character:Destroy()
    player.Character = char
    cam.CameraSubject = head
    cam.CoordinateFrame = head.CFrame * CFrame.Angles(-180, 0, 0) * CFrame.new(0, 0, 0)

        print('Set up character')
end
player.Chatted:connect(function(msg)
    if msg == "make_character" then
            spawn_pseudo_character(player)
    end
end)

1 answer

Log in to vote
1
Answered by 9 years ago

I've figured out that your problem is, indeed, your camera type selection. I've set it to custom in this block, while making a few general improvements. You may not have known that Cameras for characters are generally aimed at their humanoid. Also, I changed the neck from Weld to Motor so you can at least spin the head without the complication of CFrames. Also, it would be a better choice to nil your character rather than destroy it.

local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
cam.CameraType = "Custom"

if not workspace:FindFirstChild('Players') then
    m = Instance.new('Model', workspace)
    m.Name = 'Players'
end

function spawn_pseudo_character(player)
    if workspace.Players:FindFirstChild(player.Name) then -- character already exists, don't do it again
        return
    end
    print('Building character')
    local char = Instance.new("Model", workspace.Players)
    char.Name = player.Name

    local head = Instance.new("Part")
    head.Name = "Head"
    head.Anchored, head.Locked, head.CanCollide = false, true, true
    head.Transparency = 0
    head.FormFactor = "Symmetric"
    head.Size = Vector3.new(1, 1, 1)
    head.TopSurface, head.BottomSurface = "Smooth", "Smooth"
    head.CFrame = CFrame.new(0, 11.5, 0)
    head.Parent = char

    local torso = Instance.new("Part")
    torso.Name = "Torso"
    torso.Anchored, head.Locked, head.CanCollide = false, true, true
    torso.Transparency = 0
    torso.FormFactor = "Symmetric"
    torso.Size = Vector3.new(1, 2, 1)
    torso.TopSurface, head.BottomSurface = "Smooth", "Smooth"
    torso.CFrame = CFrame.new(0, 10, 0)
    torso.Parent = char

    local neck = Instance.new("Motor6D")
    neck.Name = "Neck"
    neck.Part0, neck.Part1 = torso, head
    neck.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
    neck.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
    neck.MaxVelocity = 0.1
    neck.Parent = torso

    print('Built character')

    local hum = Instance.new("Humanoid", char)

    player.Character = nil
    player.Character = char
    cam.CameraSubject = hum
    cam.CoordinateFrame = head.CFrame * CFrame.Angles(-180, 0, 0) * CFrame.new(0, 0, 0)

    print('Set up character')
end
player.Chatted:connect(function(msg)
    if msg == "make_character" then
        spawn_pseudo_character(player)
    end
end)
0
Thank you for the improvements, however, no character is being spawned in with this script, and I can freely move my camera around in the game as if I'm in studio. novipak 70 — 9y
0
I've only tested this in studio, I'll test it on server and see what I can do from there. HECKFURNIOUS 85 — 9y
Ad

Answer this question