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

Why is Humanoid.seated not working after I reset or get killed in my game?

I am working on a security camera system, however when a player resets or gets killed and sits on the chair again, the stuff that's supposed to happen when a player sits on the seat does not. Why is that happening? I put the script in StarterPlayerScripts by the way.

Local Script:

camera = workspace.CurrentCamera
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
securityCams = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Security")
remotes = game.ReplicatedStorage.Remotes

humanoid.Seated:Connect(function(seated, seat)
	if seated then
		securityCams.Open.Visible = true
	else
		for _, element in pairs(securityCams:GetChildren()) do
			element.Visible = false
		end
		
		repeat wait()
			camera.CameraType = Enum.CameraType.Custom
		until camera.CameraType == Enum.CameraType.Custom
	end
	
	remotes.DisableSecurity.OnClientEvent:Connect(function()
		for _, element in pairs(securityCams:GetChildren()) do
			element.Visible = false
		end
		
		repeat wait()
			camera.CameraType = Enum.CameraType.Custom
		until camera.CameraType == Enum.CameraType.Custom
	end)
end)

2 comments

0

I don't know why you would want a player to still be able to use something when realistically they are dead. But try using a .Touched event instead?

0

No I meant like after they die, when they sit down on the seat nothing happens

1 answer

Hey, I'm late on this, but for all the future people who see this:

The answer is because when you die, your humanoid is deleted and a new one replaces it. Therefore, all connections related to humanoid are destroyed. Every time a new character is added, you have to redefine that connection.

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