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

How can i make a person stay seated?

Asked by 9 years ago

I'm trying to make seats on a go kart to prevent people from getting off or jumping off the seat. What lines of a code can i add to a gokart seat to prevent someone from jumping off the seat or coming off until they are tped to lobby after they finish?

1 answer

Log in to vote
10
Answered by
Unclear 1776 Moderation Voter
9 years ago

To be honest, there is no easy way to go about this if you are limiting your view to just Seats.

That's why we are going to cheat.

Have you ever considered maybe just replicating Seat behavior with a regular part that acts as your seat? We can do this with a Part, a Weld, and a reference to the Character in question. Let's first assume that our seat part is referenced so some variable seatin our script. For example...

local seat = workspace.Seat

Then, we want to do is listen for a character to be touching the seat by hooking it up to an event. Let's try to check if the object that's touching the seat is actually a descendant of a character model as well, while we're at it...

local seat = workspace.Seat
seat.Touched:connect(function(object) -- listen to the seat and trigger this function when it is touched
    local character = 
        game.Players:GetPlayerFromCharacter(object.Parent) and 
        object.Parent -- check if object's parent is a character
    if character then -- if it is a character then
        -- some more code
    end
end)

After the character check that we did with if character then, let's weld the character to the seat! Our best bet is to use the HumanoidRootPart as one of the welded parts, because it is the root part of the character for all animations (and some other things as well). We will create a weld between our seat and our HumanoidRootPart. Make sure that both have Anchored set to false before welding or you will see some unexpected behavior!

local seat = workspace.Seat
seat.Touched:connect(function(object) -- listen to the seat and trigger this function when it is touched
    local character = 
        game.Players:GetPlayerFromCharacter(object.Parent) and 
        object.Parent -- check if object's parent is a character
    if character then -- if it is a character then
        local humanoidRootPart  = character:FindFirstChild("HumanoidRootPart") -- get humanoidrootpart
        local humanoid          = character:FindFirstChild("Humanoid") -- get humanoid
        if humanoidRootPart and  humanoid then -- if the humanoidrootpart and humanoid exists
            local weld = LoadLibrary("RbxUtility").Create("Weld")({
                Name    = "SeatWeld",
                Parent  = character,
                Part0   = seat,
                Part1   = humanoidRootPart,
                C0      = CFrame.new(0, 1.5, 0) -- we want our character slightly above the seat!
            })
             humanoid.Sit = true -- we will make them sit
        end
    end
end)

This is a bit of code for you to work off of. It's not the full solution to your problem. You will still need to implement...

  • Releasing the character when they reach the lobby (you can release characters by destroying the weld and making them jump out of the sitting position, but when this happens is up to you)

  • How to keep players in the sitting position during driving (hint: listen for the Jumping event in the humanoid)

  • Other things?

Good luck.

0
If your solution requires code to prevent the player from jumping, why not just use Roblox's seat and add a script to prevent the player from jumping? chess123mate 5873 — 9y
0
AFAIK (and I can't test at the moment), even cancelling the jumping breaks the Seat weld and ejects the Player. This code overrides that by making the Seat weld manually. adark 5487 — 9y
Ad

Answer this question