How do I make this script work?

The script below doesn’t work for some reason.

game.Players.PlayerAdded:connect(function(p)
game:GetService(‘Players’).PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild(“Humanoid”).Died:Connect(function()
wait(1)
p.CameraMaxZoomDistance = 15 --How Far You Can Zoom Out
p.CameraMinZoomDistance = 15 --How Close You Can Zoom in (First Person 0)
p.CameraMode = “Classic”
end)
end)
end)
end)

Does it have to be a LocalScript or a Server Script? Does there have to be a RemoteEvent, if so what do I do with it? Thanks.

you have same function 2 times so just remove

and the extra end) from the end

I tried doing this and it was giving me errors, could you re-write the script possibly? Maybe I did something wrong.

oh, reason was that when u change the camerasettings for the player u were using “p” still instead of “player” so this should work:

game:GetService(‘Players’).PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild(“Humanoid”).Died:Connect(function()
wait(1)
player.CameraMaxZoomDistance = 15 --How Far You Can Zoom Out
player.CameraMinZoomDistance = 15 --How Close You Can Zoom in (First Person 0)
player.CameraMode = “Classic”
end)
end)
end)

It’s still giving me errors, what do I do now?

try:

game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
wait(1)
player.CameraMaxZoomDistance = 15 --How Far You Can Zoom Out
player.CameraMinZoomDistance = 15 --How Close You Can Zoom in (First Person 0)
player.CameraMode = Enum.CameraMode.Classic
end)
end)
end)

Nope, still not working. I tried putting it as a LocalScript, tried putting it in StarterGui, StarterCharacterScripts and StarterPlayerScripts, nothing.

the script must be in workspace or serverscriptservice and it must be a regular script not localscript

If you’re using a LocalScript, the PlayerAdded Event will not fire for you as the individual player as it’ll only fire for other Players instead

You can easily reference your own player by just doing game.Players.LocalPlayer instead, and could also put this inside of StarterCharacterScripts so that the Camera will reset every time you respawn

@appe125 Unfortunately, this seems to be a Camera issue so I don’t believe changing it on the Server is really a good idea to begin with in the first place (You want to handle Camera changes on the client mostly)

local Plr = game.Players.LocalPlayer
local Char = script.parent
local Hum = Char:WaitForChild("Humanoid")

Hum.Died:Connect(function()
    Plr.CameraMaxZoomDistance = 15
    Plr.CameraMinZoomDistance = 15
    Plr.CameraMode = Enum.CameraMode.Classic
end)
1 Like

If we talk about workspace.camera then yes localsciprt is the answer but the camerasettings his changing are inside the player so it can be done serverside. and player technicly is already local

but yes the code u sent will also work