Hi! I was wondering how I would go about making someone go out of first-person when they hit a brick.
Please provide a sample or a developer hub thread.
Example:
script.Parent.Touched:Connect(function()
--script to take out of first person
end)
Make it get your player first using :GetPlayerFromCharacter() and then set the CameraMaxZoomDistance to anything you want. for example 0.5 which is the minimum
Edit:
script.Parent.Touched:Connect(function(hit)--runs the function once part is hit
if hit.Parent:FindFirstChild("Humanoid") then--checks if it finds the humanoid then its an actual player
game.Players:GetPlayerFromCharacter(hit.Parent).CameraMaxZoomDistance = 1--sets the camera zoom distance to 1.
end
end)
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:FindFirstChild(hit.Parent.Name)
if Player then
Player.CameraMinZoomDistance = 10
wait(1)
Player.CameraMinZoomDistance = 0.5
end
end)
Server scripts alone would not work. You would need to use a LocalScript for this, and perhaps a RemoteEvent. This is because the Touched event is detected on the server, but the CameraMinZoomDistance property is changed on the client. So in the server, your script would be:
local Remote = game.ReplicatedStorage:WaitForChild("ThirdPersonEvent")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Remote:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
end)
The ‘hit’ parameter would be the part touching the part, which would most likely be a child of the player’s character. But first, we must check if it is a character, by ensuring there is a Humanoid inside of it. If we do not, the script would error. Next, we fire an event to the player by using game.Players:GetPlayerFromCharacter(). Note that ThirdPersonEvent is the name of your RemoteEvent in ReplicatedStorage (make that if you haven’t). Next in a LocalScript in the player’s character, we set his CameraMinZoomDistance:
local Remote = game.ReplicatedStorage:WaitForChild("ThirdPersonEvent")
Remote.OnClientEvent:Connect(function()
game.Players.LocalPlayer.CameraMinZoomDistance = 5
end)
You would increase the number (above 5) if you wish for them to be panned further out of the camera. I think that’s about right… yes!