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

[Prevent Leaving Vehichle] Best Method?

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

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

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.

2 comments

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?

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!

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