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

Trying to make the Camera focus on a certain character's humanoid but not working?

This is in a LocalScript. The Title says it all. Error: Players.FiredDusk.PlayerGui.Aimbot?:5: attempt to get length of field 'Humanoid' (a userdata value)

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

repeat wait() until Player.Character
while wait() do
	local Hum = math.random(1, #Player.Character.Humanoid)
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = Hum
end

2 comments

1

im a litte confused are you trying to get a random body part or a random character in the game?

0

random character

1 answer

So 1st you need to find all of the player in the game, then choose one at random. I will not account for when they die.

This is only an example:-

local plrService = game:GetService('Players')
local plrs = plrService:GetPlayers()

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer


repeat wait() until Player.Character
while wait() do -- i dont know why you need a loop 
	
    Camera.CameraType = Enum.CameraType.Custom
	local subject = game.Workspace:FindFirstChild(plrs[math.random(1, #plrs)].Name) -- finds a ranom player currently in the workspace
	
	if subject then
		Camera.CameraSubject = subject.Head
		-- should be break the loop here?
		--break
	else
		-- the player was not found i dont know what you want to do?
	end
end

I don't know why you need a loop but I have tried to not change your original code as much as possible.

Hope this helps.

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