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

[Prevent Leaving Vehichle] Best Method?

Asked by 8 years ago

The goal is to prevent a character from leaving a car they are put into. My idea is to prevent the player from jumping. Is this the best method? if not what is? My Scripts: Script A

local noJump = script.NoJump:Clone()
    script.NoJump:Destroy()


function CharacterSpawned(char)
    local noJ = noJump:Clone()
    noJ.Parent = char
    Delay(0.2, function()
        noJ.Disabled = false
    end)
end

function PlayerEntered(player)
    player.CharacterAdded:connect(CharacterSpawned)
end

for _,v in pairs(game.Players:GetPlayers()) do PlayerEntered(v) end
game.Players.PlayerAdded:connect(PlayerEntered)

Script B(Inside A, Local Script)

local h = script.Parent:WaitForChild("Humanoid")

h.Changed:connect(function()
    h.Jump = false
end)

THANKS!

2 answers

Log in to vote
0
Answered by 8 years ago

TheDeadlyPanther was on the right track with disabling the player from controlling the character. Luckily you are able to completely disable player control and still allow them to drive a vehicle. The best way (to my knowledge) to remove player control is by disabling the ControlScript in PlayerScripts. Here's some functions to disable/enable players ability to exit the vehicle.

function disableControl(player)
    if player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("ControlScript") then --Checks if there's a ControlScript to disable
        player.PlayerScripts.ControlScript.Disabled=true
    end
end

function enableControl(player)
    if player:FindFirstChild("PlayerScripts") and player.PlayerScripts:FindFirstChild("ControlScript") then --Checks if there's a ControlScript to enable
        player.PlayerScripts.ControlScript.Disabled=false
    end
end
Ad
Log in to vote
-1
Answered by 8 years ago

I would do one of these two:

  1. Disable the player from controlling the character, i don't know how but you can google it or insert a free model.
  2. Anchor player should work, I think.
0
He doesn't wanna freeze them. Also if he wants them to stay in car, doesn't that mean he wants them to control the car? fireboltofdeath 635 — 8y
0
Ok nvm. Can you please upvote? i wouldn't have made this answer if the stupid system didn't restrict you. I started off with -5 points! TheDeadlyPanther 2460 — 8y

Answer this question