The CameraMode only changes on second try

Hello I dont know how to fix this, but the camera only zooms out in the second try,
if you activate the proximity prompt only one time nothing happens, but if you activate it a second time it works, how do I fix it, I want it to zoom out on the first try.

local Player = game.Players.LocalPlayer

script.Parent.Triggered:Connect(function(Player)
	Player.CameraMode = Enum.CameraMode.Classic
	Player.CameraMinZoomDistance = 3
end)

script.Parent.Triggered:Connect(function(plr)
	plr.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.teleportToOutside.Position)

end)

any help is appriciated

1 Like

Hey there. It appears that you’ve attempted to connect a function to the same event for the same object. This will cause the second connect to override the first

I did it but nothing changed:

local Player = game.Players.LocalPlayer

script.Parent.Triggered:Connect(function(Player)
	Player.CameraMode = Enum.CameraMode.Classic
	Player.CameraMinZoomDistance = 3
	
	Player.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.teleportToOutside.Position)
end)
1 Like

You still have to activate it twice for it to work?

yes i need to press it twice to work.

1 Like

Just wondering, is it a local script? And where is the proximity prompt? where is the local script located?

its a normal script and its inside the proximity prompt and the proximity prompt is inside of an part which is inside the workspace

2 Likes

I see. I thought it was a local script because of the first line. Perhaps commenting out line 1 would help?

1 Like

it still doesn’t work maybe its a roblox problem

I doubt it’s a Roblox issue. Usually it’s better to control a player’s camera from a local script. I will try to replicate this in a place in studio

2 Likes

I tried it on a module script and a local script, nothing works

2 Likes

Bruh I’m sorry. I just realized that you were trying to move the character, not the camera :skull:

Just tested it. Try waiting until your avatar is completely loaded, then give it a try. It should work the first time. Check out Instance | WaitForChild

Super helpful, especially in this case.

Here’s a nifty thing I learned a few years ago:

script.Parent.Triggered:Connect(function(Player)
	Player.CameraMode = Enum.CameraMode.Classic
	Player.CameraMinZoomDistance = 3

    -- This right here
	local character = Player.Character or Player.CharacterAdded:Wait()	

	character.HumanoidRootPart.CFrame = CFrame.new(workspace.teleportToOutside.Position)
end)

idk nothing is working and even this is not working

Oop sorry. I forgot to change it back to the way you had it. Try now?

Unnecessary code, the triggered event will only be able to run once the player is loaded so no need for WaitForChild.

I saw it that you did not change it back I already tried it it doesnt work

Not necessarily. Just as you have seen, by the time the character has loaded it has taken 2 times to get the proximity prompt to work. Please note that the line of code I provided accounts for both possibilities, whether the character has already loaded or not.

Also, yes, the triggered event will only run when the player object is loaded, not the character. He needs the character to be loaded since he’s about to teleport the player.

What’s not working? Is there an error? What’s the behavior? I’ve tested it myself and it seems to work fine.

It seems I missed a crucial part again. Please check the code I sent and try a second time.

What are you talking about? You don’t need to wait for the character to be loaded using :WaitForChild() specifically for triggering a proximity prompt because the Roblox engine ensures that the character is fully loaded and available in the game before any proximity prompt events can be triggered.