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

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

Asked by 3 years ago

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)
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? Roger111 347 — 3y
0
No I meant like after they die, when they sit down on the seat nothing happens torchmaster101 92 — 3y

1 answer

Log in to vote
0
Answered by 1 year ago

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.

Ad

Answer this question