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

How Would Make It Where If I Go Near The Car It Pops Up A GUI Saying Press F To Enter Vehicle?

I’ve already did the scripting where it pops up the screen gui but I want once I press F It’ll make me go into the nearest VehicleSeat aka car next to me.

Here’s The Script Where The GUI Would Pop Up. Please Help Finish

1
local part = workspace.Part --Change the "part" to the name of the part
2
 
3
part.Touched:connect(function() --I assume this is a local script put inside the frame.
4
    script.Parent.Visible = true
5
end)



—Also This

1
local part = workspace.Part --Change the "part" to the name of the part
2
 
3
part.Touched:connect(function() --I assume this is a local script put inside the screengui.
4
    script.Parent.Enabled = true
5
end)





1 answer

--ScreenGui->LocalScript
local ply = game.Players.LocalPlayer
local contextService = game:GetService("ContextActionService")

local function seatPlayer(car)
	--Insert your own
end
local function findClosestCars()
	local ta = game.Workspace:FindFirstChild("Cars") and  game.Workspace:FindFirstChild("Cars"):GetChildren() or game.Workspace:GetChildren()
	local closest = nil
	local root = ply.Character.HumanoidRootPart
	local max = 5
	local shortestDis = max
	for i,v in pairs(ta) do
		if v.Name == "Car" then
			local dis = (v.Seat.Position-root.Position).magnitude
			if dis < max and dis < shortestDis then
				closest = v
				shortestDis = dis
			end
		end
	end
	if closest then
		seatPlayer(closest)
	end
end

contextService:BindAction("enterCar",findClosestCars,false,Enum.KeyCode.F)

1 comment

0

I haven't scripted in a while what would I put here. "local function seatPlayer(car) --Insert your own end"

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