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

How to change the camera distance while sitting?

Asked by 9 years ago

This may seem like a weird problem... So, here I have a script in Workspace that will clone a LocalScript into the player.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        script.LocalScript:clone().Parent = character
    end)
end)

Below I have the contents of the LocalScript which as two children of NumberValues one named TPV (which is 9) and another which is not implemented yet. I want the player to have the freedom to play in first or third person which is the camera min and max zoom distance, however I want to have the zoom distances increased by the other NumberValue only when the player is sitting in a vehicle. My problem is I'm having trouble accessing Humanoid.Sit because I can't get the players name outside of the studio environment.

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character

Mouse = player:GetMouse()

thirdperson = script.TPV.Value
firstperson = 0.5

player.CameraMaxZoomDistance = thirdperson
player.CameraMinZoomDistance = thirdperson


function PressedV(key)
if key == "v" then
    if player.CameraMaxZoomDistance == thirdperson or 
    player.CameraMinZoomDistance == thirdperson then
        player.CameraMinZoomDistance = firstperson
        player.CameraMaxZoomDistance = firstperson
        wait()

    elseif player.CameraMaxZoomDistance == firstperson or 
    player.CameraMinZoomDistance == firstperson then
        player.CameraMaxZoomDistance = thirdperson
        player.CameraMinZoomDistance = thirdperson
        wait()

    end
end
end
Mouse.KeyDown:connect(PressedV)
0
Uhhh... character.Humanoid.Sit? Goulstem 8144 — 9y
0
I thought it was that simple, but it didn't seem to work... I'll try it again though. DaRtHSpeeDy 10 — 9y
0
Okay that did the trick lol. I just have to move a few lines around now. I thought character directed to game.players which was confusing me. Thanks for the help! DaRtHSpeeDy 10 — 9y

Answer this question