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

Using scripts to change player's size while having player camera still in it's head part?

Asked by 5 years ago

I need this for a first-person horror game I'm working on, I want the player to be a little bigger / taller than what the normal robloxian size is, and once in first person, I don't think the camera changes it's position according to the player's head's location. Is there a way to do this? Thank you in advance.

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

I believe the camera actually initially follows the humanoid of a player, so I'll first write a line of code demonstrating how to change the subject of the camera.

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

camera.CameraSubject = player.Character.Head
camera.CFrame = player.Character.Head.CFrame
camera.FieldOfView = 70

The line

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

Checks to make sure the player's character is valid before moving on in the Local Script, it is not required if the function you are using had a fired event, such as .Touched or .Changed

To Set the Camera to "First Person" you can enact the following property:

local player = game.Players.LocalPlayer

player.CameraMode = Enum.CameraMode.LockFirstPerson

To get out of this, you use the setting

local player = game.Players.LocalPlayer

player.CameraMode = Enum.CameraMode.Classic

You could also change the Character's Head.CFrame using the C0 Property of the Neck Motor6D in the Head of the player's Character.

Doing this:

local player = game.Players.LocalPlayer

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

player.Character.Head.CFrame = player.Character.Head.CFrame + Vector3.new(0, 2, 0)

Or anything similar to this, will break the joint and subsequently kill the humanoid.

What you'll want to do is alter the Neck CFrame with a line of code like this:

local player = game.Players.LocalPlayer

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

player.Character.Head.Neck.C0 = CFrame.new(0, 2, 0)

In R15 Rigs, there are values that can be adjusted as shown here: https://blog.roblox.com/2016/11/customize-your-avatar-with-r15-character-scaling/

Note, that these are not found in R6, which is why I added about altering the Neck C0 (which can be done to all Motor6D in the player)

EDIT: As Requested, Removal of Accessories

There are technically two ways you can do this, since :RemoveAccessories is not working for you currently, I'll add a line of code that should.

local player = game.Players.LocalPlayer

local h = player.Character:GetDescendants()
for i = 1, #h do
    if h[i].ClassName == "Accessory" then 
        h[i]:Destroy()
    end 
end

The way you attempted can be further explored here: https://developer.roblox.com/api-reference/function/Humanoid/RemoveAccessories

However the line of code below should demonstrate how it works.

local player = game.Players.LocalPlayer

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

player.Character.Humanoid:RemoveAccessories()

Please note, for the code provided, they should be placed in a LocalScript, you can also set these properties in a Server Script with the PlayerAdded Event of game.Players like so:

game.Players.PlayerAdded:Connect(function(player)
    -- Code Here
end)
0
@SerpentineKing this is all amazing, thank you, but there's another problem now. The accessories appear and won't disappear when I find the humanoid and call :RemoveAccessories. I don't know why... aoaoaoaoa00 4 — 5y
Ad

Answer this question