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

Why does Humanoid.Seated event not work?

Asked by 4 years ago

I am trying to make make it possible for players to use certain functions once they sit down on Vehicle Seat. The Local Script is parented to StarterCharacterScripts, which activates when the player sits down on a Vehicle Seat. The issue is that once the player gets up, he is still able to use buttons, which activate the said functions. I have read that the Humanoid.Seated event still works when the player gets up from the seat, so to counteract this problem, I have introduced the if Humanoid.Sit == true then (line 8), but this line didn't work as well. Is there a problem?

local Character = script.Parent
local PlayerHumanoid = Character:WaitForChild("Humanoid")
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local Service = game:GetService("UserInputService")

PlayerHumanoid.Seated:connect(function(Sitting, CarSeat)
    if PlayerHumanoid.Sit == true then      
        Service.InputBegan:connect(function(Input, gameEvent)
            if Input.UserInputType == Enum.UserInputType.Keyboard then
                if Input.KeyCode == Enum.KeyCode.H then
                    game.Workspace.Sound:Play()
                end
                if Input.KeyCode == Enum.KeyCode.B then
                    game.ReplicatedStorage.RotateEvent:FireServer()
                end


            end
        end)

    end

end)

Answer this question