Function not working correctly

So, i am doing an LocalScript to Manipulate Camera more “easy” (despite taking me more time to do the script)

So the fact Is that the script not working, here.

In “v:FindFirstChild(value)”, It prints nothing

Script:

wait(0.1)
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("CameraPos")
local camera = workspace.CurrentCamera
local CameraPositions = workspace:WaitForChild("CameraPositions")

wait()

function cameraset(type, value)
	if type == "part" then
		for i, v in pairs(CameraPositions:GetChildren()) do
			if v:FindFirstChild(value) then
			       print(value)
				-- camera.CFrame = part.CFrame
			end
		end
	else
		print("No Part selected")
	end
	if type == "cframe" then
		camera.CFrame = CFrame.new(value, value, value)
	else
		print("No Extra CFrame Selected")
	end
end

wait(1)
cameraset("part", "Part1")


Do a print debugging process, example:

function cameraset(type, value)
    print("1")
	if type == "part" then
        print("1")
		for i, v in pairs(CameraPositions:GetChildren()) do
            print("1")
			if v:FindFirstChild(value) then
			       print(value)
				-- camera.CFrame = part.CFrame
			end
		end
	else
		print("No Part selected")
	end
	if type == "cframe" then
		camera.CFrame = CFrame.new(value, value, value)
	else
		print("No Extra CFrame Selected")
	end
end

Where does the code stop? If it stops at the first 1, it’s because type is already used by lua, rename type to part or something else.

it doesnt stop like.


, it just doesnt prints the “print(v)”

Does “yoo” exist in CameraPositions? Also it is good practice not to name variables on top of lua functions.

It was an thing i was testing, but Its a folder

image

Replace “yoo” with “Part1” and tell me if that works.

Did it, but it stills doesnt worked

Try replace v:FindFirstChild with if v.Name == value.

nNope, It seems that still doesnt work

Any errors this time? If so, please paste them.

How Strange, no errors in the output

I would also rename type to something else, lua may get confused with it. May you also resent the script with the new changes?

image

You did make the changes that I told you to make…

wait no, my wrong, wrong photo


MAN, it workedd!!!, thanksss, now it prints correctly the Part found with the Name “Part1”

Mark the post that resolved your question with a solution. You’re welcome!

Ok, first part of the problem resolved, sorry for ruining the day but i noticed this, it says “nil”, any ideas why this occurs?, this happens when i try to Set The Part Named “Part1” CFrame to Camera CFrame

image

camera.CFrame = v.CFrame

Side note: for the area which says if type == “cframe” it will error due to inputing a string into a Vector3.
Mark the response which resolved your OP.

Man yes, didnt notice, i am dumb, thanks again, Nope, it didnt gave me errors, it worked perfect