Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I repeat a script after I respawn or die?

So basically I was gonna add in a first person view of your avatar in first person like torso, legs and arms but whenever I die it resets it. I was thinking if any of the script helpers or professional scripters could help me.

--[[ Notes: Transparency Modifier is what is the end result when "zooming in", it can be changed to whatever you like.

Camera Offset is changed to allow the player to see at lower angles without clipping the view with the torso.
This may or maynot effect certian tools if they change the players camera position IE crouching or crawling.

Use:
Place into StarterPlayer.StarterChacterScripts

--]]

local character = (game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait())

game:GetService("RunService").RenderStepped:connect(function() if (character:FindFirstChild("Right Arm") and character:FindFirstChild("Left Arm")) then

	character:FindFirstChild("Right Arm").LocalTransparencyModifier = 0

	character:FindFirstChild("Left Arm").LocalTransparencyModifier = 0
	
	character:FindFirstChild("Right Leg").LocalTransparencyModifier = 0

	character:FindFirstChild("Left Leg").LocalTransparencyModifier = 0

	character:FindFirstChild("Torso").LocalTransparencyModifier = 0	
	
	character:FindFirstChild("Humanoid").CameraOffset = Vector3.new(0,0,-1)
end

end)

1 comment

0

Roblox does not provide an event for when the character has respawned, but you do have the died event, which you can time with the time that it takes to respawn to apply your required changes.

Check events section of this article.

1 answer

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character, Player)
		character:FindFirstChild("Right Arm").LocalTransparencyModifier = 0
		character:FindFirstChild("Left Arm").LocalTransparencyModifier = 0
		character:FindFirstChild("Right Leg").LocalTransparencyModifier = 0
		character:FindFirstChild("Left Leg").LocalTransparencyModifier = 0
		character:FindFirstChild("Torso").LocalTransparencyModifier = 0
		character:FindFirstChild("Humanoid").CameraOffset = Vector3.new(0,0,-1)
		character:WaitForChild("Humanoid").Died:Connect(function()
			character:FindFirstChild("Right Arm").LocalTransparencyModifier = 0
			character:FindFirstChild("Left Arm").LocalTransparencyModifier = 0
			character:FindFirstChild("Right Leg").LocalTransparencyModifier = 0
			character:FindFirstChild("Left Leg").LocalTransparencyModifier = 0
			character:FindFirstChild("Torso").LocalTransparencyModifier = 0
			character:FindFirstChild("Humanoid").CameraOffset = Vector3.new(0,0,-1)
		end)
	end)
end)

Disgusting, but works.

This discussion is preserved as it was. New answers, comments, and votes are closed.