Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Repeat Script after Died?

Asked by 4 years ago

After I died my zoom was gone I keep doing it again over and over (sorry im bad at english.)

game.Players.LocalPlayer.CameraMaxZoomDistance = 1000

2 answers

Log in to vote
0
Answered by
DogeIXX 172
4 years ago

Simply put a Script into ServerScriptService that tracks if the Player died. Then just fire the client with a RemoteEvent and put

game.Players.LocalPlayer.CameraMaxZoomDistance = 1000

into the LocalScript.

Just like that:

Script, located in ServerScriptService:

local Remoteevnt = --Location of RemoteEvent, would suggest ReplicatedStorage

game.Players.PlayerAdded:Connect(function(plr)

   plr.CharacterAdded:Connect(function(char)

      char.Humanoid.Died:Connect(function()

              Remoteevnt:FireClient(plr)
        end)
   end)
end)

LocalScript, located in StarterPlayerScripts:

local Remoteevnt = --Location of RemoteEvent

Remoteevnt.OnClientEvent:Connect(function()
     wait(game.Players.LocalPlayer.RespawnTime + 1)
     game.Players.LocalPlayer.CameraMaxZoomDistance = 1000
end)

If you get an error, feel free to write in in the comments, so I can look what the problem is.

Ad
Log in to vote
0
Answered by
stef0206 125
4 years ago

If you put the script into StarterCharacterScripts it will run every time your character respawns, to optimise it a bit better with this method though I would recommend added a line so the script looks like this

game.Players.LocalPlayer.CameraMaxZoomDistance = 1000
script:Destroy()

Hopes this Helps!

Answer this question